回退:{{通知Scheme}}(英文系统{{SCHEME}})标签以获取应用通知的Scheme #272 #276(无解,去除多余代码)

This commit is contained in:
pppscn 2024-03-17 19:15:28 +08:00
parent 1ee0c12f42
commit a4aade94c5
7 changed files with 4 additions and 49 deletions

View File

@ -78,18 +78,13 @@ data class MsgInfo(
@SuppressLint("SimpleDateFormat")
fun replaceTemplate(template: String, regexReplace: String, needJson: Boolean = false): String {
val splitSimInfo = simInfo.split("#####")
val title = splitSimInfo.getOrElse(0) { simInfo }
val scheme = splitSimInfo.getOrElse(1) { "" }
return template.replaceTag(getString(R.string.tag_from), from, needJson)
.replaceTag(getString(R.string.tag_package_name), from, needJson)
.replaceTag(getString(R.string.tag_sms), content, needJson)
.replaceTag(getString(R.string.tag_msg), content, needJson)
.replaceTag(getString(R.string.tag_card_slot), title, needJson)
.replaceTag(getString(R.string.tag_card_slot), simInfo, needJson)
.replaceTag(getString(R.string.tag_card_subid), subId.toString(), needJson)
.replaceTag(getString(R.string.tag_title), title, needJson)
.replaceTag(getString(R.string.tag_scheme), scheme, needJson)
.replaceTag(getString(R.string.tag_title), simInfo, needJson)
.replaceTag(getString(R.string.tag_uid), uid.toString(), needJson)
.replaceTag(getString(R.string.tag_receive_time), SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date), needJson)
.replaceTag(getString(R.string.tag_current_time), SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date()), needJson)

View File

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

View File

@ -2,7 +2,6 @@ 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
@ -82,43 +81,12 @@ class NotificationService : NotificationListenerService() {
//自身通知跳过
if (PACKAGE_NAME == sbn.packageName) return
// 标题
var title = extras["android.title"]?.toString() ?: ""
val title = extras["android.title"]?.toString() ?: ""
// 通知内容
var text = extras["android.text"]?.toString() ?: ""
if (text.isEmpty() && notification.tickerText != null) {
text = notification.tickerText.toString()
}
// 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()
Log.e(TAG, "Failed to get scheme from PendingIntent", e)
}
//不处理空消息(标题跟内容都为空)
if (TextUtils.isEmpty(title) && TextUtils.isEmpty(text)) return

View File

@ -624,7 +624,6 @@
<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_scheme">{{SCHEME}}</string>
<string name="tag_call_type">{{CALL_TYPE}}</string>
<string name="tag_location">{{LOCATION}}</string>
<string name="tag_location_longitude">{{LOCATION_LONGITUDE}}</string>

View File

@ -625,7 +625,6 @@
<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_scheme">{{SCHEME}}</string>
<string name="tag_call_type">{{CALL_TYPE}}</string>
<string name="tag_location">{{LOCATION}}</string>
<string name="tag_location_longitude">{{LOCATION_LONGITUDE}}</string>

View File

@ -625,7 +625,6 @@
<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_scheme">{{SCHEME}}</string>
<string name="tag_call_type">{{CALL_TYPE}}</string>
<string name="tag_location">{{LOCATION}}</string>
<string name="tag_location_longitude">{{LOCATION_LONGITUDE}}</string>

View File

@ -625,7 +625,6 @@
<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_scheme">{{SCHEME}}</string>
<string name="tag_call_type">{{CALL_TYPE}}</string>
<string name="tag_location">{{LOCATION}}</string>
<string name="tag_location_longitude">{{LOCATION_LONGITUDE}}</string>