mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-08 01:10:23 +00:00
回退:{{通知Scheme}}
(英文系统{{SCHEME}}
)标签以获取应用通知的Scheme
#272 #276(无解,去除多余代码)
This commit is contained in:
parent
1ee0c12f42
commit
a4aade94c5
@ -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)
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user