我有一个关于足球/足球的应用程序,我使用API来获取关于比赛的信息,我需要一种方法来在此API中添加目标时进行实时通知它们具有JSON格式。通过JSON格式实时通知android
0
A
回答
0
,看看谷歌云消息(GCM)服务,它正是为此而设计的。如果使用gcm不可行,则需要设置重复警报,但不会像gcm那样精确。但我强烈建议去gcm。这里有一个供您参考的链接。 GCM dev docs
对于无法访问后端源代码的情况,另一种解决方法是开发一种中间层类型的Web服务,该服务不断轮询您的后端并使用gcm来提醒客户端。至少你不会浪费用户的系统资源。
0
这是你如何弹出一个通知:
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.logo_notification)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setVibrate(new long[] { 200, 200, 200})
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id, notificationBuilder.build()); //id is the notification id, if you use the same id, the notification will override the previous
0
为了实现该功能,
- 使用服务经常(也许一次5分钟)查询有关比赛的信息。
- 如果您有任何更新,请向用户显示通知。
要显示通知:
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);
Notification notification = new NotificationCompat.Builder(getApplicationContext()).setTicker("Ticker Text").setSmallIcon("Icon").setContentTitle("Title").setContentText("Content Text").setContentIntent(pi).setAutoCancel(true).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
欲了解更多信息,如果您有机会获得你的后端Web服务代码中使用此链接 here
0
你真正想要做的是有一个Receiver
将运行并检查更新。对于实时更新,我会使用Socket。
这几乎取决于你的服务器。
相关问题
- 1. 实时通知node.js
- 2. 通过Android扩展Android通知
- 3. Android推送通知消息格式
- 4. 点击通知时通知android服务
- 5. 通过格式
- 6. 如何使用parse.com通过JSON推送通知[Android]
- 7. 从android服务创建实时通知
- 8. 通过JSON格式进行解析
- 9. 如何通过JSON特定格式
- 10. 通过实时
- 11. 在django中通过ajax实现通知
- 12. Symfony通过循环foreach将实体转换为json格式
- 13. Android通知区域风格
- 14. Android:通过C2DM推送通知
- 15. 通过服务的Android通知
- 16. 通过node.js发送android推送通知
- 17. Android Wear:如何通过通知通知智能手机
- 18. Android onCreate()未通知通知
- 19. zencoder通知json
- 20. 如何通过监听器通过Facebook SDK获取实时状态通知
- 21. Android状态栏通知 - 通过任何方式通知状态栏(烤面包)通过状态栏?
- 22. 通过自己的IP通过RTP进行Android实时音频流式传输
- 23. 如何更新Android通知时间格式?
- 24. Json发布通过Android
- 25. Android通过json登录
- 26. Android JSON数组通过URL
- 27. 想不通json格式化
- 28. Android交互式通知
- 29. Android,静音模式通知
- 30. 实时通知系统
你能发表一些代码吗? 你试过'NotificationCompat'吗? – gilgil28
我没有为此编写任何代码,但我需要一种可以在此情况下使用的方法 – Shivo
如果您在解决问题时遇到任何问题,将使用StackOverflow。至少先尝试 –