Android - 通知管理器,有一个没有意图的通知 [英] Android - notification manager, having a notification without an intent

查看:15
本文介绍了Android - 通知管理器,有一个没有意图的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够发出通知以提醒用户计时器已完成,但是我不希望在您单击通知时有意图.

I would like to be able to fire a notification to alert the users about a timer that has finished, however i do not wish to have an intent when you click the notification.

我试过为意图传入 null

I've tried passing in null for the intent

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);

int icon = R.drawable.icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();

Notification notification = new Notification(icon, tickerText, when);

CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";

notification.setLatestEventInfo(context, contentTitle, contentText, null);
mNotificationManager.notify(HELLO_ID, notification);

推荐答案

你可以传参数

PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0)

代替

null

notification.setLatestEventInfo(context, contentTitle, contentText, null);

这篇关于Android - 通知管理器,有一个没有意图的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆