问题
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