gpt4 book ai didi

安卓 : Push data with notification

转载 作者:行者123 更新时间:2023-11-30 03:07:15 25 4
gpt4 key购买 nike

我正在开发一个应用程序。该应用程序基于客户端服务器。

申请的需要是:

  1. 我想在没有网络服务的情况下将数据从服务器推送到设备,就像推送通知一样。我想推送比通知更大的数据,数据可以是文本、xml、json、.png、.jpg 任何东西。

    我试过来自 This Link 的推送通知演示

  2. 每当有额外的数据添加到服务器时,只有那些数据应该从服务器推送到设备并发出通知。当用户点击通知数据从设备显示时,不想在点击通知后通过网络服务器获取数据。

请建议我,我正在申请中。

所以请建议我应该遵循哪些步骤来完成此任务。用您宝贵的知识指导我。

最佳答案

应用的需要是:

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);
}

希望这对你有帮助。

关于安卓 : Push data with notification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21596055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com