优化:`自动任务·快捷指令` —— 执行动作:`发送短信`支持插入`变量标签`(标签适用场景参见 wiki附录3) #441
This commit is contained in:
parent
29ca4d3300
commit
40ee077ea7
|
@ -196,8 +196,8 @@ class SendSmsFragment : BaseFragment<FragmentTasksActionSendSmsBinding?>(), View
|
|||
@SuppressLint("SetTextI18n")
|
||||
private fun checkSetting(): SmsSetting {
|
||||
phoneNumbers = binding!!.etPhoneNumbers.text.toString().trim()
|
||||
if (!getString(R.string.phone_numbers_regex).toRegex().matches(phoneNumbers)) {
|
||||
throw Exception(getString(R.string.phone_numbers_error))
|
||||
if (!getString(R.string.phone_numbers_with_tag_regex).toRegex().matches(phoneNumbers)) {
|
||||
throw Exception(getString(R.string.phone_numbers_with_tag_error))
|
||||
}
|
||||
|
||||
msgContent = binding!!.etMsgContent.text.toString().trim()
|
||||
|
|
|
@ -29,7 +29,7 @@ import com.xuexiang.xutil.app.IntentUtils
|
|||
import com.xuexiang.xutil.data.DateUtils
|
||||
import com.xuexiang.xutil.resource.ResUtils.getString
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.Locale
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
class PhoneUtils private constructor() {
|
||||
|
@ -43,7 +43,7 @@ class PhoneUtils private constructor() {
|
|||
val infoList = HashMap<Int, SimInfo>()
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
println("1.版本超过5.1,调用系统方法")
|
||||
Log.d(TAG, "1.版本超过5.1,调用系统方法")
|
||||
val mSubscriptionManager = XUtil.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager
|
||||
ActivityCompat.checkSelfPermission(
|
||||
XUtil.getContext(), permission.READ_PHONE_STATE
|
||||
|
@ -53,18 +53,18 @@ class PhoneUtils private constructor() {
|
|||
//1.1.1 有使用的卡,就遍历所有卡
|
||||
for (subscriptionInfo in activeSubscriptionInfoList) {
|
||||
val simInfo = SimInfo()
|
||||
simInfo.mCarrierName = subscriptionInfo.carrierName.toString()
|
||||
simInfo.mIccId = subscriptionInfo.iccId.toString()
|
||||
simInfo.mCarrierName = subscriptionInfo.carrierName?.toString()
|
||||
simInfo.mIccId = subscriptionInfo.iccId?.toString()
|
||||
simInfo.mSimSlotIndex = subscriptionInfo.simSlotIndex
|
||||
simInfo.mNumber = subscriptionInfo.number.toString()
|
||||
simInfo.mCountryIso = subscriptionInfo.countryIso.toString()
|
||||
simInfo.mNumber = subscriptionInfo.number?.toString()
|
||||
simInfo.mCountryIso = subscriptionInfo.countryIso?.toString()
|
||||
simInfo.mSubscriptionId = subscriptionInfo.subscriptionId
|
||||
println(simInfo.toString())
|
||||
Log.d(TAG, simInfo.toString())
|
||||
infoList[simInfo.mSimSlotIndex] = simInfo
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println("2.版本低于5.1的系统,首先调用数据库,看能不能访问到")
|
||||
Log.d(TAG, "2.版本低于5.1的系统,首先调用数据库,看能不能访问到")
|
||||
val uri = Uri.parse("content://telephony/siminfo") //访问raw_contacts表
|
||||
val resolver: ContentResolver = XUtil.getContext().contentResolver
|
||||
val cursor = resolver.query(
|
||||
|
@ -81,7 +81,7 @@ class PhoneUtils private constructor() {
|
|||
simInfo.mNumber = cursor.getString(cursor.getColumnIndex("number"))
|
||||
simInfo.mCountryIso = cursor.getString(cursor.getColumnIndex("mcc"))
|
||||
//val id = cursor.getString(cursor.getColumnIndex("_id"))
|
||||
println(simInfo.toString())
|
||||
Log.d(TAG, simInfo.toString())
|
||||
infoList[simInfo.mSimSlotIndex] = simInfo
|
||||
} while (cursor.moveToNext())
|
||||
cursor.close()
|
||||
|
@ -93,7 +93,7 @@ class PhoneUtils private constructor() {
|
|||
}
|
||||
//仍然获取不到/只获取到一个->取出备注
|
||||
/*if (infoList.isEmpty() || infoList.size == 1) {
|
||||
println("3.直接取出备注框的数据作为信息")
|
||||
Log.d(TAG, "3.直接取出备注框的数据作为信息")
|
||||
//为空,两个卡都没有获取到信息
|
||||
if (infoList.isEmpty()) {
|
||||
//卡1备注信息不为空
|
||||
|
@ -142,7 +142,7 @@ class PhoneUtils private constructor() {
|
|||
}
|
||||
}
|
||||
}*/
|
||||
Log.e(TAG, infoList.toString())
|
||||
Log.i(TAG, infoList.toString())
|
||||
return infoList
|
||||
}
|
||||
|
||||
|
@ -169,10 +169,21 @@ class PhoneUtils private constructor() {
|
|||
@SuppressLint("SoonBlockedPrivateApi", "DiscouragedPrivateApi")
|
||||
@RequiresPermission(permission.SEND_SMS)
|
||||
fun sendSms(subId: Int, mobileList: String, message: String): String? {
|
||||
if (TextUtils.isEmpty(mobileList) || TextUtils.isEmpty(message)) {
|
||||
Log.e(TAG, "mobileList or message is empty!")
|
||||
return "mobileList or message is empty!"
|
||||
}
|
||||
|
||||
val mobiles = mobileList.replace(";", ";").replace(",", ";").replace(",", ";")
|
||||
Log.d(TAG, "subId = $subId, mobiles = $mobiles, message = $message")
|
||||
val mobileArray = mobiles.split(";".toRegex()).toTypedArray()
|
||||
for (mobile in mobileArray) {
|
||||
Log.d(TAG, "mobile = $mobile")
|
||||
if (!isValidPhoneNumber(mobile)) {
|
||||
Log.e(TAG, "mobile ($mobile) is invalid!")
|
||||
continue
|
||||
}
|
||||
|
||||
try {
|
||||
val sendFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) PendingIntent.FLAG_IMMUTABLE else PendingIntent.FLAG_ONE_SHOT
|
||||
val sendPI = PendingIntent.getBroadcast(XUtil.getContext(), 0, Intent(), sendFlags)
|
||||
|
@ -559,6 +570,12 @@ class PhoneUtils private constructor() {
|
|||
}
|
||||
}
|
||||
|
||||
//判断是否是手机号码(宽松判断)
|
||||
private fun isValidPhoneNumber(phoneNumber: String): Boolean {
|
||||
val regex = Regex("^\\+?\\d{3,20}$")
|
||||
return regex.matches(phoneNumber)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
init {
|
||||
|
|
|
@ -93,11 +93,11 @@
|
|||
android:id="@+id/et_phone_numbers"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/phone_numbers_hint"
|
||||
android:hint="@string/phone_numbers_with_tag_hint"
|
||||
android:singleLine="true"
|
||||
app:met_clearButton="true"
|
||||
app:met_errorMessage="@string/phone_numbers_error"
|
||||
app:met_regexp="@string/phone_numbers_regex"
|
||||
app:met_errorMessage="@string/phone_numbers_with_tag_error"
|
||||
app:met_regexp="@string/phone_numbers_with_tag_regex"
|
||||
app:met_validateOnFocusLost="true"
|
||||
tools:ignore="TouchTargetSizeCheck,TextContrastCheck" />
|
||||
|
||||
|
|
|
@ -705,7 +705,10 @@
|
|||
<string name="phone_numbers">Phone Numbers</string>
|
||||
<string name="phone_numbers_hint">Required, separate multiple phone numbers with semicolons</string>
|
||||
<string name="phone_numbers_error">Invalid Phone Numbers, eg. 15888888888;19999999999</string>
|
||||
<string name="phone_numbers_regex">^\\d+(;\\d+)*$</string>
|
||||
<string name="phone_numbers_regex">^(\\+?\\d{3,20})(;\\+?\\d{3,20})*$</string>
|
||||
<string name="phone_numbers_with_tag_hint">Required, separate multiple phone numbers or tag with semicolons</string>
|
||||
<string name="phone_numbers_with_tag_error">Invalid Phone Numbers, eg. 15888888888;{{FROM}};{{SMS###\s*SMS,{([^}]+)},{([^}]+)}\s*===$1}}</string>
|
||||
<string name="phone_numbers_with_tag_regex">^((\\+?\\d{3,20})|\\{\\{([^#]+)(?:###([^=]+)===(.*?))?\\}\\})(;((\\+?\\d{3,20})|\\{\\{([^#]+)(?:###([^=]+)===(.*?))?\\}\\}))*$</string>
|
||||
<string name="msg_content">Msg Content</string>
|
||||
<string name="msg_content_hint">Required, one entry within 70 characters, more than 70 characters, one entry for every additional 64 characters</string>
|
||||
<string name="msg_content_error">Msg Content cannot be empty, up to 390 characters (6 SMS)</string>
|
||||
|
|
|
@ -706,7 +706,10 @@
|
|||
<string name="phone_numbers">手机号码</string>
|
||||
<string name="phone_numbers_hint">必填,多个手机号用半角分号分隔</string>
|
||||
<string name="phone_numbers_error">手机号码格式错误,例:15888888888;19999999999</string>
|
||||
<string name="phone_numbers_regex">^([+]?\\d+)(;[+]?\\d+)*$</string>
|
||||
<string name="phone_numbers_regex">^(\\+?\\d{3,20})(;\\+?\\d{3,20})*$</string>
|
||||
<string name="phone_numbers_with_tag_hint">必填,多个手机号或标签用半角分号分隔</string>
|
||||
<string name="phone_numbers_with_tag_error">手机号码格式错误,例:15888888888;{{FROM}};{{SMS###\s*SMS,{([^}]+)},{([^}]+)}\s*===$1}}</string>
|
||||
<string name="phone_numbers_with_tag_regex">^((\\+?\\d{3,20})|\\{\\{([^#]+)(?:###([^=]+)===(.*?))?\\}\\})(;((\\+?\\d{3,20})|\\{\\{([^#]+)(?:###([^=]+)===(.*?))?\\}\\}))*$</string>
|
||||
<string name="msg_content">短信内容</string>
|
||||
<string name="msg_content_hint">必填,70个字符内算一条,超过70个字符,每增加64字符累加1条</string>
|
||||
<string name="msg_content_error">短信内容不能为空,最多390字符(6条短信)</string>
|
||||
|
|
|
@ -706,7 +706,10 @@
|
|||
<string name="phone_numbers">手機號碼</string>
|
||||
<string name="phone_numbers_hint">必填,多個手機號用半角分號分隔</string>
|
||||
<string name="phone_numbers_error">手機號碼格式錯誤,例:15888888888;19999999999</string>
|
||||
<string name="phone_numbers_regex">^([+]?\\d+)(;[+]?\\d+)*$</string>
|
||||
<string name="phone_numbers_regex">^(\\+?\\d{3,20})(;\\+?\\d{3,20})*$</string>
|
||||
<string name="phone_numbers_with_tag_hint">必填,多個手機號或標籤用半角分號分隔</string>
|
||||
<string name="phone_numbers_with_tag_error">手機號碼格式錯誤,例:15888888888;{{FROM}};{{SMS###\s*SMS,{([^}]+)},{([^}]+)}\s*===$1}}</string>
|
||||
<string name="phone_numbers_with_tag_regex">^((\\+?\\d{3,20})|\\{\\{([^#]+)(?:###([^=]+)===(.*?))?\\}\\})(;((\\+?\\d{3,20})|\\{\\{([^#]+)(?:###([^=]+)===(.*?))?\\}\\}))*$</string>
|
||||
<string name="msg_content">簡訊內容</string>
|
||||
<string name="msg_content_hint">必填,70個字符內算一條,超過70個字符,每增加64字符累加1條</string>
|
||||
<string name="msg_content_error">簡訊內容不能為空,最多390字符(6條簡訊)</string>
|
||||
|
|
|
@ -732,7 +732,10 @@
|
|||
<string name="phone_numbers">手机号码</string>
|
||||
<string name="phone_numbers_hint">必填,多个手机号用半角分号分隔</string>
|
||||
<string name="phone_numbers_error">手机号码格式错误,例:15888888888;19999999999</string>
|
||||
<string name="phone_numbers_regex">^([+]?\\d+)(;[+]?\\d+)*$</string>
|
||||
<string name="phone_numbers_regex">^(\\+?\\d{3,20})(;\\+?\\d{3,20})*$</string>
|
||||
<string name="phone_numbers_with_tag_hint">必填,多个手机号或标签用半角分号分隔</string>
|
||||
<string name="phone_numbers_with_tag_error">手机号码格式错误,例:15888888888;{{FROM}};{{SMS###\s*SMS,{([^}]+)},{([^}]+)}\s*===$1}}</string>
|
||||
<string name="phone_numbers_with_tag_regex">^((\\+?\\d{3,20})|\\{\\{([^#]+)(?:###([^=]+)===(.*?))?\\}\\})(;((\\+?\\d{3,20})|\\{\\{([^#]+)(?:###([^=]+)===(.*?))?\\}\\}))*$</string>
|
||||
<string name="msg_content">短信内容</string>
|
||||
<string name="msg_content_hint">必填,70个字符内算一条,超过70个字符,每增加64字符累加1条</string>
|
||||
<string name="msg_content_error">短信内容不能为空,最多390字符(6条短信)</string>
|
||||
|
|
Loading…
Reference in New Issue