Android12中禁止使用「跳转连接」追踪通知点击。
创始人
2024-09-30 22:30:23
0

为了支持在Android 12中追踪通知的点击事件,需要使用“Notification Trampoline”方式。这使得通知点击打开的activity仅仅是中介去除了主活动和通知之间的直接链接。以下是示例代码展示如何使用“Notification Trampoline”方式进行追踪通知点击事件:

先在AndroidManifest.xml中定义一个activity(即用于通知跳转的中介):


    
        
        
        
        
    

然后在创建Notification的时候,设置setContentIntent():

val intent = Intent(context, NotificationTrampolineActivity::class.java).apply {
    data = Uri.parse("your-scheme://your-host")
    flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}

val pendingIntent = PendingIntent.getActivity(
    context,
    0,
    intent,
    PendingIntent.FLAG_CANCEL_CURRENT
)

val notificationBuilder = NotificationCompat.Builder(context, CHANNEL_ID)
    .setContentIntent(pendingIntent)
    .setSmallIcon(R.drawable.notification_icon)
    .setContentTitle(title)
    .setContentText(message)

NotificationTrampolineActivity将被用作接收到上述意图的入口点。在该活动的onCreate()方法中,从Intent中提取所需的信息,然后从Notification中启动适当的Activity:

class NotificationTrampolineActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        handleIntent(intent)
        finish()
    }

    private fun handleIntent(intent: Intent) {
        val uri

相关内容

热门资讯

透视步骤!wepoker有辅助... 透视步骤!wepoker有辅助工具吗,wepoker有没有辅助(透视)确实真的有挂(哔哩哔哩)1、w...
透视手筋!如何判断wpk辅助软... 透视手筋!如何判断wpk辅助软件的真假,werplan透视挂(透视)一贯存在有挂(哔哩哔哩);小薇(...
透视操作!pokerworld... 透视操作!pokerworld破解版下载,wepoker有机器人吗(透视)真是存在有挂(哔哩哔哩)1...
透视步骤!wpk插件,大菠萝手... 透视步骤!wpk插件,大菠萝手游辅助(透视)都是有挂(哔哩哔哩)1、完成大菠萝手游辅助辅助器v3.3...
透视指引!wepoker手机助... 透视指引!wepoker手机助手,epoker透视(透视)本来真的有挂(哔哩哔哩);该软件可以轻松地...
透视方式!德州hhpoker脚... 透视方式!德州hhpoker脚本,wepoker数据分析(透视)真是真的是有挂(哔哩哔哩)wepok...
透视课程!wepoker安装教... 透视课程!wepoker安装教程,epoker有透视吗(透视)本来是有挂(哔哩哔哩)1、操作简单,无...
透视窍门!hhpoker外开挂... 透视窍门!hhpoker外开挂靠谱吗,wepoker插件辅助(透视)都是是有挂(哔哩哔哩)1、该软件...
透视教程书!wepoker脚本... 透视教程书!wepoker脚本,wepoker免费脚本弱密码(透视)竟然真的有挂(哔哩哔哩)1、每一...
透视诀窍!德州透视是真的假的,... 透视诀窍!德州透视是真的假的,hhpoker哪个俱乐部靠谱(透视)都是是有挂(哔哩哔哩)1、透视诀窍...