Dee*_*pti 4 notifications android
这是在服务启动时发出通知的代码
NotificationCompat.Builder mbuild = new NotificationCompat.Builder(getApplicationContext());
Intent in = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent resultIN = PendingIntent.getActivity(getApplicationContext(),code,in,NOTIFICATION_COUNT); mbuild.setSmallIcon(R.drawable.images1);
mbuild.setContentText(NOTIFICATION_COUNT +" New Message");
mbuild.setContentIntent(resultIN); //mbuild.addAction(R.drawable.notifications,NOTIFICATION_COUNT +"New Messages",resultIN);
NotificationManager nmagr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nmagr.notify(1, mbuild.build());
Run Code Online (Sandbox Code Playgroud)
每个人都正常工作..代码打开目标活动,但通知仍然保留在通知栏中.我尝试过使用mbuil.setautocancel(true); 但它无所事事
试试这个
NotificationManager nmagr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification=mbuild.build();
notification.flags = Notification.FLAG_AUTO_CANCEL;
nmagr.notify(1,notification);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2386 次 |
| 最近记录: |