android - open wrong App via Notification click in same Android device
问题描述
I am develop in Android Notification.
I create the own notification like the following.
const val NotifiTAG = "NotiTag"
val mNotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
//random request code
val randomId = List(3) { badge + Random().nextInt(badge+99999) }
val intentView = Intent(this, Main2Activity::class.java)
repIntent = PendingIntent.getActivity(this, randomId[0], intentView, PendingIntent.FLAG_UPDATE_CURRENT)
val builder = NotificationCompat.Builder(applicationContext,NOTIFICATION_CHANNEL)
.setContentTitle(title)
.setContentText(description)
.setAutoCancel(true)
.setContentIntent(repIntent)
.setDefaults(Notification.DEFAULT_VIBRATE)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
//Set channel , when SDK >= 26
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
//Set Channel
val channel = NotificationChannel(NOTIFICATION_CHANNEL, "ubauth",
NotificationManager.IMPORTANCE_HIGH)
channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
channel.enableVibration(true)
channel.setShowBadge(true)
mNotificationManager.createNotificationChannel(channel)
}
val notification = builder.build()
ShortcutBadger.applyNotification(applicationContext, notification, badge)
mNotificationManager.notify(NotifiTAG,badge, notification)
The above code work fine for receive Notification, and it can open the App when click notification when only one App in Android device.
When I install two identical App with different build types and different applicationId. The notification open the wrong App when I click the notification .
Did i missing something ? Thanks in advance.
解决方案
尝试将特定应用的组件名称添加到您的意图中
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.your.app",
"com.your.app.Main2Activity"));
推荐阅读
- regex - 2个数字和一个符号的正则表达式
- racket - >:期望一个真实的,给定的(无效)
- html - WGAC - 顺序降序
- java - 需要使用 JSch Java 库将 SSH 从 E2c 服务器连接到第二台服务器的帮助吗?
- node.js - 如何访问条件 CrudRequest nestjsx
- angular - @HostListener 不会触发 window:scroll 事件
- python - 如何选择在 django 表单字段中显示的选项?
- python - 如何遍历 json 文件中的间隔并创建数据框?
- python - S3 对象没有属性 Bucket
- python - Selenium 无法通过 id 找到元素,但它存在