Android:使用通知推送数据

Android:使用通知推送数据,android,notifications,push-notification,push,Android,Notifications,Push Notification,Push,我正在开发一个应用程序。该应用程序基于客户机-服务器 申请的需要是: 我想在没有web服务的情况下将数据从服务器推送到设备,就像推送通知一样。我想推送比通知更大的数据,数据可以是文本、xml、json、.png、.jpg任何东西 我已经尝试了推送通知演示 每当有额外的数据添加到服务器时,只有这些数据应该通过通知从服务器推送到设备。当用户单击从设备获取显示的通知数据时,不希望在单击web服务器的通知后获取数据 请告诉我我正在申请中 因此,请建议我应该采取什么步骤来完成这项任务。请用您宝贵的知识指导

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


申请的需要是:

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

    我已经尝试了推送通知演示

  • 每当有额外的数据添加到服务器时,只有这些数据应该通过通知从服务器推送到设备。当用户单击从设备获取显示的通知数据时,不希望在单击web服务器的通知后获取数据

  • 请告诉我我正在申请中

    因此,请建议我应该采取什么步骤来完成这项任务。请用您宝贵的知识指导我。

    检查此项


    注意:确保您使用GCM的“服务器密钥”而不是“android密钥”作为“API密钥”。

    应用程序的需要是:

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

    这可能会对您有所帮助。

    此链接用于推送通知。但是我想用notification.1推送数据、图像或文件。您可以从第三方服务器在请求正文中添加数据。2.对于图像,您可以发送图像链接或图像的base64格式。注意:GCM仅支持在通知中发送4kb的数据。还以JSON结构发送请求正文。您可以在事件回调“onNotificationGCM”中的“Message”开关大小写标记中访问此数据。接收到的数据是JSON格式的,您可以通过“e.payload.your_JSON_data_key”访问它。您可以使用chrome的高级rest客户端创建服务器请求,而不是ruby脚本。