mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-09 19:10:51 +00:00
新增:彩信转发功能(试验) #351
This commit is contained in:
parent
9ac3548719
commit
ac74a183cd
@ -25,6 +25,8 @@
|
||||
tools:ignore="ScopedStorage" />
|
||||
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_MMS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
|
||||
<uses-permission android:name="android.permission.READ_SMS" />
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||
|
@ -317,6 +317,10 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
|
||||
if (isChecked) {
|
||||
//检查权限是否获取
|
||||
XXPermissions.with(this)
|
||||
// 接收 WAP 推送消息
|
||||
.permission(Permission.RECEIVE_WAP_PUSH)
|
||||
// 接收彩信
|
||||
.permission(Permission.RECEIVE_MMS)
|
||||
// 接收短信
|
||||
.permission(Permission.RECEIVE_SMS)
|
||||
// 发送短信
|
||||
@ -1000,14 +1004,7 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
|
||||
if (isChecked) {
|
||||
XXPermissions.with(this).permission(Permission.ACCESS_COARSE_LOCATION).permission(Permission.ACCESS_FINE_LOCATION).permission(Permission.ACCESS_BACKGROUND_LOCATION).request(object : OnPermissionCallback {
|
||||
override fun onGranted(permissions: List<String>, all: Boolean) {
|
||||
//重启前台服务
|
||||
val serviceIntent = Intent(requireContext(), ForegroundService::class.java)
|
||||
serviceIntent.action = "START"
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
requireContext().startForegroundService(serviceIntent)
|
||||
} else {
|
||||
requireContext().startService(serviceIntent)
|
||||
}
|
||||
restartForegroundService()
|
||||
}
|
||||
|
||||
override fun onDenied(permissions: List<String>, never: Boolean) {
|
||||
@ -1020,12 +1017,26 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding?>(), View.OnClickL
|
||||
}
|
||||
SettingUtils.enableLocationTag = false
|
||||
switchEnableLocationTag.isChecked = false
|
||||
restartForegroundService()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
restartForegroundService()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//重启前台服务
|
||||
private fun restartForegroundService() {
|
||||
val serviceIntent = Intent(requireContext(), ForegroundService::class.java)
|
||||
serviceIntent.action = "START"
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
requireContext().startForegroundService(serviceIntent)
|
||||
} else {
|
||||
requireContext().startService(serviceIntent)
|
||||
}
|
||||
}
|
||||
|
||||
//获取当前手机品牌
|
||||
private fun getAutoStartTips(): String {
|
||||
return when (Build.BRAND.lowercase(Locale.ROOT)) {
|
||||
|
@ -31,14 +31,36 @@ class SmsReceiver : BroadcastReceiver() {
|
||||
if (SettingUtils.enablePureClientMode) return
|
||||
|
||||
//过滤广播
|
||||
if (intent.action != Telephony.Sms.Intents.SMS_RECEIVED_ACTION && intent.action != Telephony.Sms.Intents.SMS_DELIVER_ACTION) return
|
||||
if (intent.action != Telephony.Sms.Intents.SMS_RECEIVED_ACTION
|
||||
&& intent.action != Telephony.Sms.Intents.SMS_DELIVER_ACTION
|
||||
&& intent.action != Telephony.Sms.Intents.WAP_PUSH_RECEIVED_ACTION
|
||||
&& intent.action != Telephony.Sms.Intents.WAP_PUSH_DELIVER_ACTION
|
||||
) return
|
||||
|
||||
var from = ""
|
||||
var message = ""
|
||||
if (intent.action == Telephony.Sms.Intents.WAP_PUSH_RECEIVED_ACTION || intent.action == Telephony.Sms.Intents.WAP_PUSH_DELIVER_ACTION) {
|
||||
from = intent.getStringExtra("address") ?: ""
|
||||
message = intent.getStringExtra("body") ?: ""
|
||||
Log.d(TAG, "from = $from, message = $message")
|
||||
|
||||
val bundle = intent.extras
|
||||
bundle?.let {
|
||||
for (key in bundle.keySet()) {
|
||||
val obj = bundle.get(key)
|
||||
if (obj is ByteArray) {
|
||||
val data = String(obj)
|
||||
// 解析彩信内容
|
||||
parseMMSContent(data, from)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (smsMessage in Telephony.Sms.Intents.getMessagesFromIntent(intent)) {
|
||||
from = smsMessage.displayOriginatingAddress
|
||||
message += smsMessage.messageBody
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "from = $from, message = $message")
|
||||
|
||||
//短信指令
|
||||
@ -124,4 +146,56 @@ class SmsReceiver : BroadcastReceiver() {
|
||||
SmsCommandUtils.execute(context, smsCommand)
|
||||
}
|
||||
|
||||
private fun parseMMSContent(data: String, sender: String?) {
|
||||
// 在这里实现解析彩信内容的逻辑
|
||||
Log.d("MMSReceiver", "Received MMS from: $sender, Data: $data")
|
||||
|
||||
val parts = data.split("\n\n") // 假设彩信内容以两个换行符 "\n\n" 分隔不同部分
|
||||
parts.forEach { part ->
|
||||
val lines = part.split("\n")
|
||||
var contentType: String? = null
|
||||
var content: String? = null
|
||||
var contentTransferEncoding: String? = null
|
||||
|
||||
lines.forEach { line ->
|
||||
Log.d(TAG, "Line: $line")
|
||||
val keyValue = line.split(":")
|
||||
if (keyValue.size == 2) {
|
||||
val key = keyValue[0].trim()
|
||||
val value = keyValue[1].trim()
|
||||
|
||||
when (key.toLowerCase()) {
|
||||
"content-type" -> contentType = value
|
||||
"content-transfer-encoding" -> contentTransferEncoding = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理不同 MIME 类型的内容
|
||||
contentType?.let {
|
||||
when {
|
||||
it.startsWith("text") -> {
|
||||
// 文本内容
|
||||
content = lines.last() // 假设文本内容在当前部分的最后一行
|
||||
// 处理文本内容,例如展示在 TextView 中
|
||||
Log.d(TAG, "Text data: $content")
|
||||
}
|
||||
|
||||
it.startsWith("image") -> {
|
||||
// 图片内容
|
||||
// 如果 contentTransferEncoding 表示 base64 编码
|
||||
if (contentTransferEncoding.equals("base64", true)) {
|
||||
content = lines.last() // 假设图片数据在当前部分的最后一行
|
||||
// 解码图片数据并展示或保存图片
|
||||
val decodedImage = android.util.Base64.decode(content, android.util.Base64.DEFAULT)
|
||||
// 处理解码后的图片数据
|
||||
Log.d(TAG, "Image data: $decodedImage")
|
||||
}
|
||||
}
|
||||
// 可以根据其他 MIME 类型继续添加处理逻辑,比如视频、音频等
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user