在android中移动其他活动时禁用通知
我必须开发一个一键通知应用程序 我喜欢:在android中移动其他活动时禁用通知,android,push-notification,google-cloud-messaging,Android,Push Notification,Google Cloud Messaging,我必须开发一个一键通知应用程序 我喜欢: @Override protected void onMessage(Context context, Intent intent) { Log.i(TAG, "Received message"); GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); regId = GCMRegistrar.getRegistrationId(this);
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
regId = GCMRegistrar.getRegistrationId(this);
String message = intent.getExtras().getString("offer");
displayMessage(context, message);
// notifies user
if(Constants.response != null){
generateNotification(context,message);
}
}
private static void generateNotification(Context context,String message) {
int icon = R.drawable.icon;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, MyDealProducts.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}
在此,在已登录的客户上成功生成通知
现在,我没有在访问这些通知的同时注销客户表单,这意味着我不需要启用通知
但是这里的通知是启用的。我如何在客户注销后禁用通知
请给我一个建议???为此,您可以在用户注销时取消生成的通知 使用
NotificationManager
的方法cancel(int-id)
(其中id是通知id,在您的情况下是其0
)或cancelAll()