I am trying to develop a java server to send push notifications in my application.
I was able to send a notification, but I have two problems ...
The message text does not appear in the status bar (only the application name is displayed)
When I click on the notification in the status bar, nothing happens (without opening the application)
This is my java server code:
//ArrayList<String> userGcmList = new ArrayList<String>(); ArrayList<String> userRegIdGcmList = new ArrayList<String>(); //my phone userRegIdGcmList.add("***********"); int numverOfDevicesRegisterd = userRegIdGcmList.size(); try { //AI KEY Sender sender = new Sender("*****************"); // use this line to send message with payload data Message message = new Message.Builder() .collapseKey("1") .timeToLive(3) .delayWhileIdle(true) .addData("message", "Text in the status bar does not appear") .build(); // Use this for multicast messages MulticastResult result = sender.send(message, userRegIdGcmList, numverOfDevicesRegisterd); sender.send(message, userRegIdGcmList, numverOfDevicesRegisterd); System.out.println(result.toString()); if (result.getResults() != null) { int canonicalRegId = result.getCanonicalIds(); if (canonicalRegId != 0) { } } else { int error = result.getFailure(); System.out.println(error); } } catch (Exception e) { e.printStackTrace(); }
I open port 5228 on my router, but it does not change ...
and the source in my application:
private static void generateNotification(Context context, String message) {
long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.ic_launcher, message, when); notification.defaults |= Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_AUTO_CANCEL; String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, LauncherActivity.class);
Micka source share