新增:`{{通知Scheme}}`(英文系统`{{SCHEME}}`)标签以获取应用通知的`Scheme`(试验性,暂时无解了) #272 #276

pull/335/head
pppscn 1 year ago
parent 8250049439
commit 8953981d4e

@ -41,7 +41,7 @@ data class MsgInfo(
val versionName = AppUtils.getAppVersionName()
val splitSimInfo = simInfo.split("#####")
val title = splitSimInfo.getOrElse(0) { simInfo }
val schema = splitSimInfo.getOrElse(1) { "" }
val scheme = splitSimInfo.getOrElse(1) { "" }
val titleForSend: String = template.replace(getString(R.string.tag_from), from)
.replace(getString(R.string.tag_package_name), from)
.replace(getString(R.string.tag_sms), content)
@ -49,7 +49,7 @@ data class MsgInfo(
.replace(getString(R.string.tag_card_slot), title)
.replace(getString(R.string.tag_card_subid), subId.toString())
.replace(getString(R.string.tag_title), title)
.replace(getString(R.string.tag_schema), schema)
.replace(getString(R.string.tag_scheme), scheme)
.replace(getString(R.string.tag_receive_time), SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date))
.replace(getString(R.string.tag_device_name), deviceMark)
.replace(getString(R.string.tag_app_version), versionName)
@ -87,7 +87,7 @@ data class MsgInfo(
val versionName = AppUtils.getAppVersionName()
val splitSimInfo = simInfo.split("#####")
val title = splitSimInfo.getOrElse(0) { simInfo }
val schema = splitSimInfo.getOrElse(1) { "" }
val scheme = splitSimInfo.getOrElse(1) { "" }
val smsVoForSend: String = customSmsTemplate.replace(getString(R.string.tag_from), from)
.replace(getString(R.string.tag_package_name), from)
.replace(getString(R.string.tag_sms), content)
@ -95,7 +95,7 @@ data class MsgInfo(
.replace(getString(R.string.tag_card_slot), title)
.replace(getString(R.string.tag_card_subid), subId.toString())
.replace(getString(R.string.tag_title), title)
.replace(getString(R.string.tag_schema), schema)
.replace(getString(R.string.tag_scheme), scheme)
.replace(getString(R.string.tag_receive_time), SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date))
.replace(getString(R.string.tag_device_name), deviceMark)
.replace(getString(R.string.tag_app_version), versionName)

@ -109,10 +109,10 @@ class LogsFragment : BaseFragment<FragmentLogsBinding?>(), MsgPagingAdapter.OnIt
if (item.msg.type == "app") {
val splitSimInfo = item.msg.simInfo.split("#####")
val title = splitSimInfo.getOrElse(0) { item.msg.simInfo }
val schema = splitSimInfo.getOrElse(1) { "" }
val scheme = splitSimInfo.getOrElse(1) { "" }
detailStr.append(ResUtils.getString(R.string.title)).append(title).append("\n\n")
detailStr.append(ResUtils.getString(R.string.msg)).append(item.msg.content).append("\n\n")
if (!TextUtils.isEmpty(schema) && schema != "null") detailStr.append(ResUtils.getString(R.string.schema)).append(schema).append("\n\n")
if (!TextUtils.isEmpty(scheme) && scheme != "null") detailStr.append(ResUtils.getString(R.string.scheme)).append(scheme).append("\n\n")
} else {
detailStr.append(ResUtils.getString(R.string.msg)).append(item.msg.content).append("\n\n")
detailStr.append(ResUtils.getString(R.string.slot)).append(item.msg.simInfo).append("\n\n")

@ -1,6 +1,8 @@
package com.idormy.sms.forwarder.service
import android.annotation.SuppressLint
import android.content.ComponentName
import android.net.Uri
import android.os.Build
import android.service.notification.NotificationListenerService
import android.service.notification.StatusBarNotification
@ -43,14 +45,15 @@ class NotifyService : NotificationListenerService() {
}
}
@SuppressLint("DiscouragedPrivateApi")
override fun onNotificationPosted(sbn: StatusBarNotification?) {
try {
//纯客户端模式
if (SettingUtils.enablePureClientMode) return
//异常通知跳过
if (sbn!!.notification == null) return
if (sbn.notification.extras == null) return
val notification = sbn?.notification ?: return
val extras = notification.extras ?: return
//自动消除额外APP通知
if (!TextUtils.isEmpty(SettingUtils.cancelExtraAppNotify)) {
@ -76,25 +79,48 @@ class NotifyService : NotificationListenerService() {
val from = sbn.packageName
//自身通知跳过
if (PACKAGE_NAME == sbn.packageName) return
//通知标题
var title = ""
if (sbn.notification.extras["android.title"] != null) {
title = sbn.notification.extras["android.title"].toString()
if (extras["android.title"] != null) {
title = extras["android.title"].toString()
}
//通知内容
var text = ""
if (sbn.notification.extras["android.text"] != null) {
text = sbn.notification.extras["android.text"].toString()
if (extras["android.text"] != null) {
text = extras["android.text"].toString()
}
if (text.isEmpty() && sbn.notification.tickerText != null) {
text = sbn.notification.tickerText.toString()
if (text.isEmpty() && notification.tickerText != null) {
text = notification.tickerText.toString()
}
//通知Schema
val schema = sbn.notification.extras["android.template"].toString()//.substringBefore('/')
Log.d(TAG, "schema=$schema")
if (!TextUtils.isEmpty(schema)) {
title += "#####$schema"
// TODO: 获取Scheme信息
val pendingIntent = notification.contentIntent
/*try {
val method = pendingIntent.javaClass.getDeclaredMethod("getIntent")
val intent = method.invoke(pendingIntent) as Intent
// 获取scheme
val scheme = intent.scheme
if (scheme != null) {
// 处理scheme信息
Log.d(TAG, "Scheme: $scheme")
}
} catch (e: Exception) {
// 处理异常
Log.e(TAG, "Failed to get scheme from PendingIntent", e)
}*/
try {
val creatorPackage = pendingIntent.creatorPackage
val appIntent = creatorPackage?.let { packageManager.getLaunchIntentForPackage(it) }
var scheme: String? = appIntent?.scheme
if (scheme == null) {
val uri: Uri? = appIntent?.data
scheme = uri?.scheme
}
Log.d(TAG, "from=$from, scheme=$scheme")
if (!TextUtils.isEmpty(scheme)) {
title += "#####$scheme"
}
} catch (e: Exception) {
e.printStackTrace()
}
//不处理空消息(标题跟内容都为空)

@ -572,7 +572,7 @@
<string name="rematch">Rematch</string>
<string name="from">From: </string>
<string name="title">Title: </string>
<string name="schema">Schema: </string>
<string name="scheme">Scheme: </string>
<string name="msg">Msg: </string>
<string name="slot">Slot: </string>
<string name="rule">Rule: </string>
@ -592,7 +592,7 @@
<string name="tag_device_name">{{DEVICE_NAME}}</string>
<string name="tag_app_version">{{APP_VERSION}}</string>
<string name="tag_title">{{TITLE}}</string>
<string name="tag_schema">{{SCHEMA}}</string>
<string name="tag_scheme">{{SCHEME}}</string>
<string name="rule_sms">SMS</string>
<string name="rule_call">CALL</string>
<string name="rule_app">APP</string>

@ -573,7 +573,7 @@
<string name="rematch">重新匹配规则</string>
<string name="from">来源:</string>
<string name="title">标题:</string>
<string name="schema">Schema</string>
<string name="scheme">Scheme</string>
<string name="msg">消息:</string>
<string name="slot">卡槽:</string>
<string name="rule">规则:</string>
@ -593,7 +593,7 @@
<string name="tag_device_name">{{设备名称}}</string>
<string name="tag_app_version">{{当前应用版本号}}</string>
<string name="tag_title">{{通知标题}}</string>
<string name="tag_schema">{{通知Schema}}</string>
<string name="tag_scheme">{{通知Scheme}}</string>
<string name="rule_sms">短信</string>
<string name="rule_call">来电</string>
<string name="rule_app">应用</string>

Loading…
Cancel
Save