Manoj Fegde
Manoj Fegde

Reputation: 4761

Android : Push data with notification

I am developing an application. The application is client server based.

The need of application is that:

  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.

    I had tried the push notification demo from This Link

  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.

Please suggest me i am in middle of my application.

So please suggest me what steps should I follow to achieve this task. Guide me with your valuable knowledge.

Upvotes: 1

Views: 1444

Answers (2)

Optim India
Optim India

Reputation: 476

The need of application is that:

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.

You can push data in the form of payload as we can send message from server to device. But the maximum size of data we can send is 4KB.

You just check following code as :

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

May this will help you.

Upvotes: 1

user3059993
user3059993

Reputation: 344

check this link.

Note: Make sure you use GCM's "server key" instead of "android key" for "API key".

Upvotes: 0

Related Questions