具体的数据应该根据您的Deep Link URI来配置(例如host,pathPrefix和scheme)。
FLAG_ACTIVITY_NEW_TASK
标志:Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
onNewIntent()
方法中处理Deep Link:@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
// handle Deep Link here
}
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Title")
.setContentText("Content")
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.build();
NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, notification);
这些步骤应该能够解决Deep Link通知在Android 12中无法工作的问题。