Android, send push notification to myself

微笑、不失礼 提交于 2020-08-10 23:45:36

问题


I want to an user send a push notification for himself.

Is there a way to do that without using Google Cloud Messaging?

It is offline, just show a notification on his own phone.

Thanks.


回答1:


example for building and sending a notification:

from: 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); 

you can edit the notification as you like.

also helpful:

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

happy coding...



来源:https://stackoverflow.com/questions/24331696/android-send-push-notification-to-myself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!