【发布时间】:2014-10-27 19:10:04
【问题描述】:
根据Google Developers Guide,我正在实施this 代码。
一切正常,我可以成功收到通知数据。
如果您检查 GCMIntentService.java 文件的第 70 行,它会将此行回显到 LogCat:
I/GCM Demo(6653): Working... 1/5 @ 8656981
I/GCM Demo(6653): Working... 2/5 @ 8657982
I/GCM Demo(6653): Working... 3/5 @ 8658983
I/GCM Demo(6653): Working... 4/5 @ 8659983
I/GCM Demo(6653): Working... 5/5 @ 8660984
I/GCM Demo(6653): Completed work @ 8661985
I/GCM Demo(6653): Received: Bundle[{msg=messagehere, from=SENDERIDHERE, android.support.content.wakelockid=3, collapse_key=do_not_collapse}]
所以我的设备正在接收通知数据,但设备的状态栏中没有可见的通知。什么都没有发生。
你能告诉我为什么这些推送通知没有显示在我的设备上,只显示在 LogCat 中吗?
更新
- Manifest file
-
这是我的 sendNotification() 方法:
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setContentTitle("GCM Notification") .setStyle(new NotificationCompat.BigTextStyle() .bigText(msg)) .setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
【问题讨论】:
-
将您的代码发布到您正在创建通知的位置(
sendNotification在您链接的代码中)。 -
尝试在第 106 行使用
(int) (System.currentTimeMillis() & 0xfffffff);代替NOTIFICATION_ID。只是一个疯狂的猜测。还可以尝试在清单文件中使用 Intent 服务类的完整路径。 -
@ianhanniballake 已发布。谢谢。
-
@Rohit5k2 ,试过了。没有任何改变。
-
您是否尝试使用
GCMIntentService.java的完整路径?
标签: java android notifications push-notification