在我的应用程序中尝试这么多解决方案,但直到没有工作点击通知重定向另一个activity.Please给我适当的解决方案,因为我尝试了这么多的解决方案,我也尝试export = true,单顶。我的代码附在此链接上,请找到并给我解决方案
=> https://www.dropbox.com/sh/vguv249ame7zid0/AABDaqjdkMEsFmPagxH3F8U4a?dl=0
Intent resultIntent = new Intent(this, RedirectToLeaderboard.class);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Random r = new Random();
notifyID = r.nextInt(30000 - 1) + 1;
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, notifyID, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent.getService(getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mNotifyBuilder;
NotificationManager mNotificationManager;
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotifyBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.mipmap.notification_all_icon).setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.notification_all_icon));
// Set pending intent
mNotifyBuilder.setContentIntent(resultPendingIntent);
mNotificationManager.notify(notifyID, mNotifyBuilder.build());
答案 0 :(得分:0)
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, notifyID, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent.getService(getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
将其替换为
Intent intent = new Intent(getApplicationContext(), YourActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), REQUEST_CODE, intent, PendingIntent.FLAG_ONE_SHOT);
答案 1 :(得分:0)
您可能需要查看handling compatibility上的notifications,其中提到了:
并非所有通知功能都可用于特定版本,即使设置它们的方法位于支持库类NotificationCompat.Builder中。
要确保最佳兼容性,请使用
NotificationCompat
及其子类创建通知,尤其是NotificationCompat.Builder
。此外,在实施通知时请遵循以下流程:
希望有所帮助!
答案 2 :(得分:0)
我的代码很完美,我得到了解决方案..
Intent resultIntent = new Intent(this, RedirectToLeaderboard.class);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Random r = new Random();
notifyID = r.nextInt(30000 - 1) + 1;
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, notifyID, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent.getService(getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mNotifyBuilder;
NotificationManager mNotificationManager;
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotifyBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.mipmap.notification_all_icon).setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.notification_all_icon));
// Set pending intent
mNotifyBuilder.setContentIntent(resultPendingIntent);
mNotificationManager.notify(notifyID, mNotifyBuilder.build());