Android 单击时通知未重定向
重定向工作正常,但如果在大约2秒钟内立即单击推送通知,则不会发生重定向。第二次我确保在任何地方等待10-15秒左右,这一次效果很好。 有人能帮我解决这个问题吗Android 单击时通知未重定向,android,push-notification,android-pendingintent,Android,Push Notification,Android Pendingintent,重定向工作正常,但如果在大约2秒钟内立即单击推送通知,则不会发生重定向。第二次我确保在任何地方等待10-15秒左右,这一次效果很好。 有人能帮我解决这个问题吗 Notification notification; Intent notificationIntent = BMSNotificationIntent.getNotificationIntent(notificationData, mContext, mSharedPreferencesM
Notification notification;
Intent notificationIntent = BMSNotificationIntent.getNotificationIntent(notificationData, mContext,
mSharedPreferencesManager, true);
notificationIntent.putExtras(rawNotificaionData);
PendingIntent NotificationPendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mContext);
notificationBuilder.setPriority(Notification.PRIORITY_MAX);
notificationBuilder
.setSmallIcon(R.drawable.status_icon)
.setColor(ContextCompat.getColor(mContext, R.color.transparent))
.setContentIntent(NotificationPendingIntent)
.setTicker(notificationData.getCleverTapTitle())
.setAutoCancel(isAutoCancelable())
.setContentTitle(notificationData.getCleverTapTitle())
.setContentText(notificationData.getCleverTapMessage())
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setDefaults(NotificationCompat.DEFAULT_VIBRATE | NotificationCompat.DEFAULT_SOUND);
notificationBuilder.setDefaults(Notification.DEFAULT_SOUND);
notificationBuilder.setChannelId(NotificationChannelName.GENERAL);
/*Create a Delete Intent that will be called when user removes the notification by swiping or by clear*/
notificationBuilder.setDeleteIntent(getNotificationDeletePendingIntent());
notification = notificationBuilder.build();
notification.flags |= NotificationCompat.FLAG_AUTO_CANCEL;
if (BMSUiUtility.isNotificationFromInbox(rawNotificaionData, mSharedPreferencesManager)) {
mNotificationManager.notify(notificationId, notification);
} else {
mNotificationManager.notify(0, notification);
}
请使用以下代码片段:) 否则
请使用以下代码片段:) 否则
解决方案:
Intent intent1 = new Intent(activity, ResultActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent1.putExtra(Extras.EXTRA_NOTIFICATION_ID, true);
intent1.putExtra("notificationId", EXPORT_NOTIFICATION_ID);
Log.i(TAG, "onPostExecute: app is BackGround ");
pendingIntent = PendingIntent.getActivity(activity, EXPORT_NOTIFICATION_ID, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
mNotifyManager.cancel(EXPORT_NOTIFICATION_ID);
Intent buttonIntent = new Intent(activity, NotificationReceiver.class);
buttonIntent.putExtra("notificationId", EXPORT_NOTIFICATION_ID);
PendingIntent dismissIntent = PendingIntent.getBroadcast(activity, 0, buttonIntent, 0);
builder.addAction(android.R.drawable.ic_menu_view, "VIEW", pendingIntent);
builder.addAction(android.R.drawable.ic_delete, "DISMISS", dismissIntent);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mContext);
notificationBuilder.setPriority(Notification.PRIORITY_MAX);
notificationBuilder
.setSmallIcon(R.drawable.status_icon)
.setColor(ContextCompat.getColor(mContext, R.color.transparent))
.setContentIntent(NotificationPendingIntent)
.setTicker(notificationData.getCleverTapTitle())
.setAutoCancel(isAutoCancelable())
.setContentTitle(notificationData.getCleverTapTitle())
.setContentText(notificationData.getCleverTapMessage())
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setDefaults(NotificationCompat.DEFAULT_VIBRATE | NotificationCompat.DEFAULT_SOUND);
notificationBuilder.setDefaults(Notification.DEFAULT_SOUND);
notificationBuilder.setChannelId(NotificationChannelName.GENERAL);
/*Create a Delete Intent that will be called when user removes the notification by swiping or by clear*/
notificationBuilder.setDeleteIntent(getNotificationDeletePendingIntent());
notification = notificationBuilder.build();
notification.flags |= NotificationCompat.FLAG_AUTO_CANCEL;
if (BMSUiUtility.isNotificationFromInbox(rawNotificaionData, mSharedPreferencesManager)) {
mNotificationManager.notify(notificationId, notification);
} else {
mNotificationManager.notify(0, notification);
}
使用以下代码取消MainActivity onDestroyMathod调用的通知:
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
在这段代码中,总是有相同的id用于通知。如果需要取消不同的通知,则必须保存用于创建通知的ID。解决方案:
Intent intent1 = new Intent(activity, ResultActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent1.putExtra(Extras.EXTRA_NOTIFICATION_ID, true);
intent1.putExtra("notificationId", EXPORT_NOTIFICATION_ID);
Log.i(TAG, "onPostExecute: app is BackGround ");
pendingIntent = PendingIntent.getActivity(activity, EXPORT_NOTIFICATION_ID, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
mNotifyManager.cancel(EXPORT_NOTIFICATION_ID);
Intent buttonIntent = new Intent(activity, NotificationReceiver.class);
buttonIntent.putExtra("notificationId", EXPORT_NOTIFICATION_ID);
PendingIntent dismissIntent = PendingIntent.getBroadcast(activity, 0, buttonIntent, 0);
builder.addAction(android.R.drawable.ic_menu_view, "VIEW", pendingIntent);
builder.addAction(android.R.drawable.ic_delete, "DISMISS", dismissIntent);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mContext);
notificationBuilder.setPriority(Notification.PRIORITY_MAX);
notificationBuilder
.setSmallIcon(R.drawable.status_icon)
.setColor(ContextCompat.getColor(mContext, R.color.transparent))
.setContentIntent(NotificationPendingIntent)
.setTicker(notificationData.getCleverTapTitle())
.setAutoCancel(isAutoCancelable())
.setContentTitle(notificationData.getCleverTapTitle())
.setContentText(notificationData.getCleverTapMessage())
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setDefaults(NotificationCompat.DEFAULT_VIBRATE | NotificationCompat.DEFAULT_SOUND);
notificationBuilder.setDefaults(Notification.DEFAULT_SOUND);
notificationBuilder.setChannelId(NotificationChannelName.GENERAL);
/*Create a Delete Intent that will be called when user removes the notification by swiping or by clear*/
notificationBuilder.setDeleteIntent(getNotificationDeletePendingIntent());
notification = notificationBuilder.build();
notification.flags |= NotificationCompat.FLAG_AUTO_CANCEL;
if (BMSUiUtility.isNotificationFromInbox(rawNotificaionData, mSharedPreferencesManager)) {
mNotificationManager.notify(notificationId, notification);
} else {
mNotificationManager.notify(0, notification);
}
使用以下代码取消MainActivity onDestroyMathod调用的通知:
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
在这段代码中,总是有相同的id用于通知。如果您有不同的通知需要取消,您必须保存用于创建通知的ID。发布您的代码please@lzzuddiin Added@dev_mg99请检查我的答案,可能有助于您发布代码please@lzzuddiin Added@dev_mg99请检查我的答案,如果我使用此//执行此操作,可能会对您有所帮助与我们的PendingEvent.send()关联;这将自动重定向到活动关联意图,而不执行通知单击。如果我正在使用此//请执行与PendingEvent.send()关联的操作;这将自动重定向到活动关联意图,而无需执行通知单击。