执行操作点击Android通知 [英] Perform an action clicking notifications in android

查看:91
本文介绍了执行操作点击Android通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想正确地创建通知,但因为当你点击通知我不能执行的操作。我希望你能帮助我,或提供一些线索。

I am trying to create notifications correctly, but as I can not perform an action when you click on the notification. I hope you can help me or give some clue.

推荐答案

建议使用 Notification.Builder NotificationCompat.Builder 从构建通知的支持库。

It is recommended to use Notification.Builder and NotificationCompat.Builder from the support library for building notifications.

此外,为什么使用重用意图这是由引起你的广播接收器?它应该是指你想通过点击来启动实际活动。

Also why do use reuse the Intent which was caught by your BroadcastReceiver? It should refer to the actual activity which you want to launch by click.

例如:

Intent intent = new Intent(context, MainActivity.class);

Notification notification = new NotificationCompat.Builder(context)
                .setContentTitle(contentTitle)
                .setContentText(contentText)
                .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0))
                .setAutoCancel(true)
                .build();

如果你并不真的想推出一些活动,你可以开始一个服务或发送广播消息,而不是。请参见的PendingIntent

If you doesn't really want to launch some activity, you may start a Service or send a broadcast message instead. See PendingIntent.

这篇关于执行操作点击Android通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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