大佬教程收集整理的这篇文章主要介绍了android – 通知不打开Acivity onCLick,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
notificationmanager notificationmanager = (notificationmanager) context .getSystemservice(Context.NOTIFICATION_serviCE); Intent intent = new Intent(context,messageReceivedActivity.class); intent.putExtra("payload",payload); intent.setAction(Long.toString(System.currentTimeMillis())); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOp); PendingIntent pendingIntent = PendingIntent.getActivity(context,intent,PendingIntent.FLAG_CANCEL_CURRENT); Notification.builder notification = new Notification.builder(context) .setContenttitle("message Received") .setsmallIcon(R.drawable.icon) .setContentText(payload) .setContenTintent(pendingIntent) .setAutoCancel(true); Notification notificationn = notification.getNotification(); notificationmanager.notify(0,notificationn);
Notification.builder notification = new Notification.builder(context) .setContenTintent(getDialogPendingIntent(Text,intentName)); private PendingIntent getDialogPendingIntent(String dialogText,String intentName) { return PendingIntent.getActivity( context,dialogText.hashCode(),new Intent(ACTION_DIALOG) .putExtra(Intent.EXTRA_TEXT,dialogText) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .setAction(intentName),0); }
如果需要,您可以更改addFlags或putExtra.
如果使用Intent Name调用不起作用,请使用类似的类,它必须工作:
Intent notificationIntent = new Intent(MainActivity.this,TestActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOp); PendingIntent intent = PendingIntent.getActivity(MainActivity.this,notificationIntent,0); notificationmanager notificationmanager = (notificationmanager) MainActivity.this .getSystemservice(Context.NOTIFICATION_serviCE); Notification.builder notification = new Notification.builder(MainActivity.this) .setContenttitle("message Received") .setsmallIcon(R.drawable.ic_launcher) .setAutoCancel(true) .setContenTintent(intent); Notification notificationn = notification.getNotification(); notificationmanager.notify(1,notificationn);
以上是大佬教程为你收集整理的android – 通知不打开Acivity onCLick全部内容,希望文章能够帮你解决android – 通知不打开Acivity onCLick所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。