繁体   English   中英

Android,向我发送推送通知

[英]Android, send push notification to myself

我想向用户发送自己的推送通知。

有没有不使用Google Cloud Messaging的方法?

它处于离线状态,只需在自己的手机上显示通知即可。

谢谢。

构建和发送通知的示例:

来自: 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

快乐的编码...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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