Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Commit

Permalink
Add tricky support for Android5
Browse files Browse the repository at this point in the history
You should place a png file "notification_icon.png" in platforms/android/res/raw/notification_icon.png
  • Loading branch information
Mehdy Dara committed Jun 22, 2015
1 parent 4f1b342 commit 80267eb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/android/com/plugin/gcm/GCMIntentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.os.Build;

import com.google.android.gcm.GCMBaseIntentService;

Expand Down Expand Up @@ -94,7 +96,7 @@ public void createNotification(Context context, Bundle extras) {

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setDefaults(defaults)
.setSmallIcon(context.getApplicationInfo().icon)
.setSmallIcon(getNotificationIcon(context))
.setWhen(System.currentTimeMillis())
.setContentTitle(extras.getString("title"))
.setTicker(extras.getString("title"))
Expand Down Expand Up @@ -133,6 +135,18 @@ private static String getAppName(Context context) {
return (String) appName;
}

private int getNotificationIcon(Context context) {
boolean isLollipop = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;

if (isLollipop) {
Resources r = getResources();

return r.getIdentifier("notification_icon", "raw", context.getPackageName());
}

return context.getApplicationInfo().icon;
}

@Override
public void onError(Context context, String errorId) {
Log.e(TAG, "onError - errorId: " + errorId);
Expand Down

0 comments on commit 80267eb

Please sign in to comment.