简体   繁体   中英

Android, send push notification to myself

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM