我正在开发一个应用程序。该应用程序是基于客户端服务器的。
应用的需要是:
我想在没有Web服务的情况下将数据从服务器推送到设备,就像推送通知一样。我想推送与通知相比更大的数据,该数据可能是文本,xml,json,.png,.jpg等任何东西。
我已经尝试过This Link的推送通知演示
每当服务器上添加了额外的数据时,只有该数据应随通知一起从服务器推送到设备。当用户单击通知数据时,将从设备显示通知数据,不想在通过Web服务器单击通知后获取数据。
请建议我我正在申请中。
因此,请建议我应该遵循哪些步骤来完成此任务。用您的宝贵知识指导我。
最佳答案
应用的需要是:
1. I want to push data from server to device without web service, As like push notification. I want to push data which are more in size as compare to the notification and the data may be text, xml, json, .png, .jpg any thing.
2. Whenever there is extra data added to the server, only that data should push from server to device with notification. When user click on the notification data gets display from device, don't want to fetch data after click on the notification with web server.
您可以以有效负载的形式推送数据,因为我们可以将消息从服务器发送到设备。但是我们可以发送的最大数据量是4KB。
您只需检查以下代码即可:
private static void generateNotification(Context context, String message) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "Message received", System.currentTimeMillis());
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
//adding LED lights to notification
notification.defaults |= Notification.DEFAULT_LIGHTS;
Intent intent = new Intent(context, MessageReceivedActivity.class);
intent.putExtra("payload", payload);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
notification.setLatestEventInfo(context, "Message", "New message received", pendingIntent);
notificationManager.notify(0, notification);
}
愿这对您有帮助。