I am working on Gcm Push Notification.Its working fine.I am able to get Notifications if app is in closed position also.I mean if i closed the app at that time also i am getting notification.But the problem here is triggered logo in notification bar.If app is opened I am getting Trigger logo properly.If app is closed I am getting white rectangualr background instead of image in Notification.I am sending screenshot please see my notification named as
Car and Bike.
and my push notification code is:
public class GCMPushReceiverService extends GcmListenerService {
//This method will be called on every new message received
String json1;
final static String GROUP_KEY_EMAILS = "group_key_emails";
public final static String NEW_PUSH_MESSAGE = "CAB_newmessage";
public static String product_classified_id="";
int NOTIFICATION_ID = 10;
Intent intent;
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void onMessageReceived(String from, Bundle data) {
//Getting the message from the bundle
System.out.println("data:" + data);
Log.d("data", "data----------------->" + data);
JSONObject json = new JSONObject();
Set<String> keys = data.keySet();
System.out.println("key :" + keys);
for (String key : keys) {
try {
json.put(key, JSONObject.wrap(data.get(key)));
json1 = json.getString("key1") ;
product_classified_id=json.getString("classified_id");
System.out.println("hi Bha:" + json);
} catch(JSONException e) {
//Handle exception here
}
}
sendNotification(json1);
}
//This method is generating a notification and displaying the notification
private void sendNotification(String message) {
Intent intent = new Intent(this, ProductViewActivity.class);
//String a ="12";
//intent.putExtra("num", a);
intent.putExtra("id",product_classified_id);
sendBroadcast(new Intent("xyz"));
// startActivity(intent);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
int requestCode = 0;
PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT);
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
int color = 0xffff0000;//.setColor(color)
NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.image)//smallanch
.setContentText(message);
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.image);//.setSmallIcon(R.drawable.launcherr)
noBuilder.setAutoCancel(true)
.setLargeIcon(largeIcon)
.setSound(sound)
.setContentTitle("Car and Bike")
.setGroup(GROUP_KEY_EMAILS)
.setGroupSummary(true)
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, noBuilder.build()); //0 = ID of notification
// NOTIFICATION_ID++;
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(NEW_PUSH_MESSAGE));
}