|
|
|
@ -10,12 +10,10 @@ import android.content.pm.PackageManager |
|
|
|
import android.location.LocationManager |
|
|
|
import android.media.AudioManager |
|
|
|
import android.net.Uri |
|
|
|
import android.os.Build |
|
|
|
import android.provider.AlarmClock |
|
|
|
import android.provider.CalendarContract |
|
|
|
import android.provider.ContactsContract |
|
|
|
import android.provider.Settings |
|
|
|
import android.telephony.SmsManager |
|
|
|
import android.util.Log |
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
import com.yunqiinnovation.location_service.LocationService |
|
|
|
@ -519,16 +517,6 @@ private class SendTextMessageHandler(private val context: Context?) : FunctionHa |
|
|
|
val handler = context.let { SystemFunctionHandler(it) } |
|
|
|
|
|
|
|
return try { |
|
|
|
// 检查发送短信权限 |
|
|
|
if (!handler.checkPermissionAndGuide(Manifest.permission.SEND_SMS, "发送短信", "发送短信")) { |
|
|
|
return JSONObject().apply { |
|
|
|
put("error", JSONObject().apply { |
|
|
|
put("code", "permission_denied") |
|
|
|
put("message", "需要短信权限才能发送短信,请在权限管理中开启短信权限") |
|
|
|
}) |
|
|
|
}.toString() |
|
|
|
} |
|
|
|
|
|
|
|
val phoneNumber = handler.getPhoneNumberForContact(phone_number) |
|
|
|
if (phoneNumber.isEmpty()) { |
|
|
|
return JSONObject().apply { |
|
|
|
@ -539,24 +527,24 @@ private class SendTextMessageHandler(private val context: Context?) : FunctionHa |
|
|
|
}.toString() |
|
|
|
} |
|
|
|
|
|
|
|
// 使用SmsManager发送短信 |
|
|
|
val smsManager = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { |
|
|
|
context.getSystemService(SmsManager::class.java) |
|
|
|
} else { |
|
|
|
@Suppress("DEPRECATION") |
|
|
|
SmsManager.getDefault() |
|
|
|
val intent = Intent(Intent.ACTION_SENDTO).apply { |
|
|
|
data = Uri.parse("smsto:$phoneNumber") |
|
|
|
putExtra("sms_body", message) |
|
|
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK |
|
|
|
} |
|
|
|
|
|
|
|
// 处理长短信 |
|
|
|
val parts = smsManager.divideMessage(message) |
|
|
|
if (parts.size == 1) { |
|
|
|
smsManager.sendTextMessage(phoneNumber, null, message, null, null) |
|
|
|
if (context.packageManager?.queryIntentActivities(intent, 0)?.isNotEmpty() == true) { |
|
|
|
context.startActivity(intent) |
|
|
|
} else { |
|
|
|
smsManager.sendMultipartTextMessage(phoneNumber, null, parts, null, null) |
|
|
|
return JSONObject().apply { |
|
|
|
put("error", JSONObject().apply { |
|
|
|
put("code", "no_sms_app") |
|
|
|
put("message", "未找到可用的短信应用") |
|
|
|
}) |
|
|
|
}.toString() |
|
|
|
} |
|
|
|
|
|
|
|
JSONObject().apply { |
|
|
|
put("result", "已成功向${phone_number}发送短信") |
|
|
|
put("result", "已打开短信应用,请确认发送") |
|
|
|
put("phone", phoneNumber) |
|
|
|
put("message", message) |
|
|
|
}.toString() |
|
|
|
|