gpt4 book ai didi

Android,向自己发送推送通知

转载 作者:搜寻专家 更新时间:2023-11-01 07:58:47 25 4
gpt4 key购买 nike

我想让用户为自己发送推送通知。

有没有办法在不使用 Google 云消息传递的情况下做到这一点?

离线了,自己手机上显示一个通知即可。

谢谢。

最佳答案

构建和发送通知的示例:

来自:http://www.vogella.com/tutorials/AndroidNotifications/article.html

// prepare intent which is triggered if the
// notification is selected

Intent intent = new Intent(this, NotificationReceiver.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

// build notification
// the addAction re-use the same intent to keep the example short
Notification n = new Notification.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject")
.setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent)
.setAutoCancel(true)
.addAction(R.drawable.icon, "Call", pIntent)
.addAction(R.drawable.icon, "More", pIntent)
.addAction(R.drawable.icon, "And more", pIntent).build();


NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

notificationManager.notify(0, n);

您可以根据需要编辑通知。

也有帮助:

http://developer.android.com/training/notify-user/build-notification.html

http://developer.android.com/guide/topics/ui/notifiers/notifications.html

http://developer.android.com/reference/android/app/NotificationManager.html

http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html

快乐编码...

关于Android,向自己发送推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24331696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com