Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien-XL committed Sep 3, 2018
2 parents c8a4f18 + a04a56d commit cb306d2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Expand Up @@ -19,20 +19,30 @@
import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.NotificationChannel;
import android.app.Notification;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import android.media.RingtoneManager;

import android.net.Uri;

import android.os.Build;
import android.os.Bundle;

import android.support.v4.app.NotificationCompat;

import android.util.Log;
import android.os.Build;
import android.app.NotificationChannel;
import android.app.Notification;

import com.google.android.gms.gcm.GcmListenerService;

import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;

Expand Down Expand Up @@ -77,6 +87,12 @@ private void sendNotification(String message) {
Log.e(TAG, "!!!!!!!!! cotc.GcmNotificationIcon not configured in manifest, push notifications won't work !!!!!!!!!");
return;
}
int notificationLargeIcon = ai.metaData.getInt("cotc.GcmNotificationLargeIcon", -1);
if (notificationLargeIcon == -1) {
Log.e(TAG, "There is no large icon for push notifs, will only use default icon");
return;
}

String pushNotifName = ai.metaData.getString("cotc.GcmNotificationTitle");
if (pushNotifName == null) {
Log.e(TAG, "!!!!!!!!! cotc.GcmNotificationTitle not configured in manifest, push notifications won't work !!!!!!!!!");
Expand All @@ -99,13 +115,17 @@ private void sendNotification(String message) {
notificationBuilder = new NotificationCompat.Builder(this);

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

notificationBuilder.setSmallIcon(notificationIcon)
.setContentTitle(pushNotifName)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setPriority(Notification.PRIORITY_HIGH);
if(notificationLargeIcon != -1)
notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(currentAct.getResources(), notificationLargeIcon));

notifManager.notify(0 /* ID of notification */, notificationBuilder.build());
} catch (Exception e) {
Log.w(TAG, "Failed to handle push notification", e);
Expand Down
1 change: 1 addition & 0 deletions UnityProject/Assets/Plugins/Android/AndroidManifest.xml
Expand Up @@ -18,6 +18,7 @@
<!-- [START GCM] -->
<meta-data android:name="cotc.GcmSenderId" android:value="\ 752049070991" />
<meta-data android:name="cotc.GcmNotificationIcon" android:resource="@drawable/ic_stat_ic_notification" />
<meta-data android:name="cotc.GcmNotificationLargeIcon" android:resource="@drawable/ic_stat_ic_notification" />
<meta-data android:name="cotc.GcmNotificationTitle" android:value="Cotc sample" />
<receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
Expand Down

0 comments on commit cb306d2

Please sign in to comment.