I solved it but I no longer have the source code..sorry
I don't receive the notifications on my Android device. The messagge was sent successfully to the GCM servers. I tried them all. Can someone help me? This is the code:
GCMIntentService.java
public class GCMIntentService extends IntentService {
static SharedPreferences prefs;
static Editor editor;
Context context;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
public static final String TAG = "GCM Intent Service";
public static final int NOTIFICATION_ID = 1;
public GCMIntentService() {
super(Configuration.SENDER_ID);
}
#Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
String msg = intent.getStringExtra("message");
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.
MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
sendNotification("Send error: " + extras.toString());
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_DELETED.equals(messageType)) {
sendNotification("Deleted messages on server: " +
extras.toString());
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// This loop represents the service doing some work.
for (int i=0; i<5; i++) {
Log.i(TAG, "Working... " + (i+1)
+ "/5 # " + SystemClock.elapsedRealtime());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
Log.i(TAG, "Completed work # " + SystemClock.elapsedRealtime());
// Post notification of received message.
//sendNotification("Received: " + extras.toString());
sendNotification(msg);
Log.i(TAG, "Received: " + extras.toString());
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
private void sendNotification(String msg) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
editor.putInt("lastViewVisited", 1).commit();
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(getText(R.string.app_name).toString())
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(intent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="<MY-PACKAGE>"
android:versionCode="9"
android:versionName="2.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<!-- GCM -->
<permission android:name="<MY-PACKAGE>.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="<MY-PACKAGE>.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!-- GCM -->
<receiver android:name="<MY-PACKAGE>.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="<MY-PACKAGE>" />
</intent-filter>
</receiver>
<service android:name="<MY-PACKAGE>.GCMIntentService" android:enabled="true" />
<activity
android:name="<MY-PACKAGE>.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="<MY-PACKAGE>.PreferenceFragment"
android:label="Preferenze">
</activity>
</application>
</manifest>
GcmBroadcastReceiver.java
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GCMIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
Try:
Check if you are using the browser api key to send the message from web server to android devices.
Related
I implemented FCM Push Notifications. The main problem is when app is closed, notifications not arrive when this happen on device.
I tried a lot of thigs for that works; when notification sent the server response with "success", but I never received.
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String CHANNEL_NAME = "FCM";
private static final String CHANNEL_DESC = "Firebase Cloud Messaging";
final String TAG = "MyFirebaseMsgService";
private String id = "";
private String title = "";
private String message = "";
private String type = "";
private String module = "";
private String fcm_notification = "";
#Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("newToken", s);
getSharedPreferences("_", MODE_PRIVATE).edit().putString("fb", s).apply();
}
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d(TAG, "Message Body" + remoteMessage.getNotification().getBody());
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
id = remoteMessage.getData().get("id");
title = remoteMessage.getData().get("title");
message = remoteMessage.getData().get("message");
type = remoteMessage.getData().get("type");
fcm_notification = "Y";
}
sendNotification(remoteMessage.getNotification().getBody(), id, title, message, type, fcm_notification);
}
private void sendNotification(String body, String user_id, String title, String message, String type, String fcm_notification) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("fcm_notification", fcm_notification);
intent.putExtra("title", title);
intent.putExtra("message", message);
intent.putExtra("type", type);
intent.putExtra("id", user_id);
int uniqueInt = (int) (System.currentTimeMillis() & 0xff);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), uniqueInt, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "");
notificationBuilder.setSmallIcon(R.drawable.ic_launcher_background)
.setContentText(body)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setColor(getResources().getColor(R.color.colorAccent))
.setLights(Color.RED, 1000, 300)
.setDefaults(Notification.DEFAULT_VIBRATE)
.setSmallIcon(R.mipmap.ic_launcher);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
getString(R.string.notification_channel_id), CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT
);
channel.setDescription(CHANNEL_DESC);
channel.setShowBadge(true);
channel.canShowBadge();
channel.enableLights(true);
channel.setLightColor(Color.RED);
channel.enableVibration(true);
channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500});
assert notificationManager != null;
notificationManager.createNotificationChannel(channel);
}
assert notificationManager != null;
notificationManager.notify(0, notificationBuilder.build());
}
public static String getToken(Context context) {
return context.getSharedPreferences("_", MODE_PRIVATE).getString("fb", "empty");
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.TestNotification"
android:targetSandboxVersion="1">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name=".Utils.App"
android:allowBackup="true"
android:icon="#drawable/kl_logo"
android:label="#string/app_name"
android:networkSecurityConfig="#xml/network_security_config"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true">
<service
android:name=".Utils.ForegroundService"
android:enabled="true"
android:exported="true"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".Utils.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="#string/notification_channel_id" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/ic_launcher" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
</application>
</manifest>
Try adding enabled="true" and INTERNAL_SERVICE permission to your message service
In my application there are two receivers, one receives calls (MyReceiverCall) and the second SMS (MyReceiverSms).
When you start the app everything works fine, I get a notification when I receive an SMS or call.
But if I close the app in task Manager then nothing wants to work and all incoming SMS and calls are ignored by the receiver.
I had assumptions that can be simply service with my notification does not start, but through logs I understood that the receiver simply does not work. (But so far the assumption is that services are to blame)
My code
MyReceiverCall.class
public class MyReceiverCall extends BroadcastReceiver {
private static final String ACTION = "android.intent.action.PHONE_STATE";
#Override
public void onReceive(Context context, Intent intent) {
Log.i("123","sakuraso13 ReceiverCall");
if (intent != null && intent.getAction() != null) {
if (intent.getAction().equals(ACTION)) {
String number=intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING) & number!=null) {
// some operation with number phone
Intent intentService = new Intent(context, ServiceMain.class);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
context.startForegroundService(intentService);
}else {
context.startService(intentService);
}
}
}
}
}
}
MyReceiverSms.class
public class MyReceiverSms extends BroadcastReceiver {
private static final String TAG="MyReceiverSms";
private static final String ACTION="android.provider.Telephony.SMS_RECEIVED";
#Override
public void onReceive(Context context, Intent intent) {
Log.i("123","sakuraso13 ReceiverWorking");
if(intent != null && intent.getAction()!=null) {
if (intent.getAction().equals(ACTION)) {
// some operation with number phone
Intent intentService=new Intent(context, ServiceMain.class);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
context.startForegroundService(intentService);
}else {
context.startService(intentService);
}
}
}
}
}
}
ServiceMain.class
public class ServiceMain extends Service {
public ServiceMain() {
}
#Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundNotification();
}
showSimpleNotification();
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.service.detector">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.BROADCAST_SMS"/>
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<application
android:name="detector.sakuraso13.App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:networkSecurityConfig="#xml/network_security_config"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<service
android:name="detector.sakuraso13.Service.ServiceMain"
android:enabled="true"
android:exported="true"></service>
<receiver
android:name="detector.sakuraso13.Broadcaster.MyReceiverCall"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="2147483647">
<action android:name="android.intent.action.NEW_OUTGOING_CALL"
android:priority="2147483647"/>
<action android:name="android.intent.action.PHONE_STATE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver
android:name="detector.sakuraso13.Broadcaster.MyReceiverSms"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<activity android:name="detector.sakuraso13.Main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Sometimes in logs I can see similar when calling when the application is closed:
2019-11-19 21:57:10.978 1271-1289/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x1000010 (has extras) } to app.service.detector/detector.sakuraso13.Broadcaster.MyReceiverCall requires android.permission.READ_PRIVILEGED_PHONE_STATE due to sender android (uid 1000)
2019-11-19 21:57:13.030 1271-6637/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x1000010 (has extras) } to app.service.detector/detector.sakuraso13.Broadcaster.MyReceiverCall requires android.permission.READ_PRIVILEGED_PHONE_STATE due to sender android (uid 1000)
My application implements 5 type of Custom Notifications.
In february, everething worked fine.
I'm now working back on it and there are no Notification displayed anymore.
First, i made a test With firebase cloud messaging. A notificication is successfully shown on my devices.
Then, i tried to modify my code folowing this answer:
Notification not showing in Oreo.
Without success.
Here is my Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.philipp.us">
<uses-permission
android:name="android.permission.GET_ACCOUNTS"
android:maxSdkVersion="27" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<!-- for android -->
<!-- <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/> -->
<!-- <uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS"/> -->
<!-- <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> -->
<!-- <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /> -->
<!-- for Samsung -->
<uses-permission android:name="com.sec.android.provider.badge.permission.READ" />
<uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" />
<!-- for htc -->
<uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.htc.launcher.permission.UPDATE_SHORTCUT" />
<!-- for sony -->
<uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE" />
<uses-permission android:name="com.sonymobile.home.permission.PROVIDER_INSERT_BADGE" />
<!-- for apex -->
<uses-permission android:name="com.anddoes.launcher.permission.UPDATE_COUNT" />
<!-- for solid -->
<uses-permission android:name="com.majeur.launcher.permission.UPDATE_BADGE" />
<!-- for huawei -->
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" />
<uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS" />
<!-- for ZUK -->
<uses-permission android:name="android.permission.READ_APP_BADGE" />
<!-- for OPPO -->
<uses-permission android:name="com.oppo.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.oppo.launcher.permission.WRITE_SETTINGS" />
<!-- for EvMe -->
<uses-permission android:name="me.everything.badger.permission.BADGE_COUNT_READ" />
<uses-permission android:name="me.everything.badger.permission.BADGE_COUNT_WRITE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.INTERACT_ACROSS_USERS_FULL"
android:protectionLevel="signature"
tools:ignore="ProtectedPermissions" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.example.philipp.android.MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Translucent"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information.
-->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.example.philipp.android.ConversationActivity"
android:label="#string/menu_item_conversations"
android:windowSoftInputMode="stateHidden|adjustResize" />
<service android:name="com.example.philipp.android.PushMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="com.example.philipp.android.PushIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<!--
Set custom default icon. This is used when no icon is set for incoming notification messages.
-->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/ic_launcher" />
<!--
Set color used with incoming notification messages. This is used when no color is set for the incoming
-->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
<activity
android:name="com.example.philipp.android.UserProfileActivity"
android:label="#string/menu_item_userprofile"
android:windowSoftInputMode="stateHidden|adjustPan" />
<provider
android:name="com.example.philipp.android.GenericFileProvider"
android:authorities="${applicationId}.my.package.name.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" />
</provider>
<receiver
android:name="com.example.philipp.android.PushMessagingService$NotificationReceiver"
android:exported="false">
<intent-filter>
<action android:name="NOTIFICATION_RECEIVE" />
</intent-filter>
</receiver>
<activity
android:name="com.example.philipp.android.SubscriptionActivity"
android:label="#string/title_activity_subscription"
android:theme="#style/AppTheme.NoActionBar"/>
</application>
</manifest>
and this is my first Custom Notifications:
DataBaseHelper2 dbHelper2;
File storageDir;
Context context;
FirebaseStorage storage = FirebaseStorage.getInstance();
public PushMessagingService() {
context = this;
}
public static class NotificationID {
private static final AtomicInteger c = new AtomicInteger(5);
public static int getID() {
return c.incrementAndGet();
}
}
public static int notifbadgeCount = 0;
final String TAG = "PushMessageReceiver";
#RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
notifbadgeCount++;
ShortcutBadger.applyCount(context, notifbadgeCount); //for 1.1.4+
dbHelper2 = new DataBaseHelper2();
storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
Log.d(TAG, remoteMessage.toString());
final Map<String, String> data = remoteMessage.getData();
Log.d(TAG, data.get("message") + " " + data.get("sender") + " " + data.get("sender_id") + " " + data.get("type") + " " + data.get("id") + " " + data.get("photo"));
int icon = R.drawable._logo_us_without_bkgrdxxxhdpi;
long when = System.currentTimeMillis();
if (isRunning(this) && data.get("type").equals("greeting")) {
Log.d(TAG, "GREETING");
}
//KEYWORD MATCH
if (data.get("type").equals("question")) {
Log.d(TAG, "QUESTION");
// Get the layouts to use in the custom notification
//NORMALSIZE
//Set Notification remote Layout
RemoteViews notificationLayoutkeywordmatch = new RemoteViews(getPackageName(), R.layout.notification_keywordmatch);
//User Photo
notificationLayoutkeywordmatch.setImageViewResource(R.id.img_userprofilpic, R.drawable._btn_addprofilpicmdpi);
//Header
notificationLayoutkeywordmatch.setImageViewResource(R.id.img_applogo, R.drawable._logo_us_without_bkgrdmdpi);
notificationLayoutkeywordmatch.setTextViewText(R.id.notification_app_name, "ask Us");
notificationLayoutkeywordmatch.setTextViewText(R.id.lbl_date_and_time, DateUtils.formatDateTime(this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME));
notificationLayoutkeywordmatch.setImageViewResource(R.id.img_notification_type, R.drawable._ic_questionxxxhdpi);
notificationLayoutkeywordmatch.setImageViewResource(R.id.notification_arrow_down, R.drawable.simple_arrow_downmdpi);
//Body
notificationLayoutkeywordmatch.setTextViewText(R.id.notification_keywordmatch_text, getString(R.string.notif_keyword_match));
notificationLayoutkeywordmatch.setTextViewText(R.id.notification_keywordmatch_sender, data.get("sender"));
notificationLayoutkeywordmatch.setTextViewText(R.id.notification_keywordmatch_question, data.get("message"));
//EXSTENDED SIZE
//Set Notification remote Layout
RemoteViews notificationLayoutkeywordmatchexpanded = new RemoteViews(getPackageName(), R.layout.notification_keywordmatchexpanded);
//User Photo
notificationLayoutkeywordmatchexpanded.setImageViewResource(R.id.img_userprofilpic, R.drawable._btn_addprofilpicmdpi);
//Header
notificationLayoutkeywordmatchexpanded.setImageViewResource(R.id.img_applogo, R.drawable._logo_us_without_bkgrdmdpi);
notificationLayoutkeywordmatchexpanded.setTextViewText(R.id.notification_app_name, "ask Us");
notificationLayoutkeywordmatchexpanded.setTextViewText(R.id.lbl_date_and_time, DateUtils.formatDateTime(this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME));
notificationLayoutkeywordmatchexpanded.setImageViewResource(R.id.notification_arrow_up, R.drawable.simple_arrow_upmdpi);
//Body
notificationLayoutkeywordmatchexpanded.setTextViewText(R.id.notification_keywordmatch_text, getString(R.string.notif_keyword_match));
notificationLayoutkeywordmatchexpanded.setImageViewResource(R.id.img_notification_type, R.drawable._ic_questionxxxhdpi);
notificationLayoutkeywordmatchexpanded.setTextViewText(R.id.notification_keywordmatch_sender, data.get("sender")+ ":");
notificationLayoutkeywordmatchexpanded.setTextViewText(R.id.notification_keywordmatch_question, data.get("message"));
//Set Notification Channel
final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int notificationId = 1;
String channelId = "channel-01";
String channelName = "Someone could need you";
int importance = NotificationManager.IMPORTANCE_HIGH;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(
channelId, channelName, importance);
mNotificationManager.createNotificationChannel(mChannel);
}
//Set Pending Intent
final Intent ii = new Intent(context.getApplicationContext(), ConversationActivity.class);
ii.putExtra("questionId", data.get("id"));
ii.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, ii, PendingIntent.FLAG_UPDATE_CURRENT);
// Apply the layouts to the notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable._logo_us_without_bkgrdmdpi)
.setCustomContentView(notificationLayoutkeywordmatch)
.setCustomBigContentView(notificationLayoutkeywordmatchexpanded)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setChannelId(channelId);
// Build notification
final Notification notification = mBuilder.build();
final NotificationTarget notificationTarget = new NotificationTarget(context, R.id.img_userprofilpic, notificationLayoutkeywordmatch, notification, 0);
final NotificationTarget notificationTargetExpanded = new NotificationTarget(context, R.id.img_userprofilpic, notificationLayoutkeywordmatchexpanded, notification, 0);
new Handler(Looper.getMainLooper()).post(new Runnable() {
#Override
public void run() {
Glide.with(getApplicationContext())
.asBitmap()
.load(data.get("photo"))
.into(notificationTarget);
Glide.with(getApplicationContext())
.asBitmap()
.load(data.get("photo"))
.into(notificationTargetExpanded);
}
});
mNotificationManager.notify(notificationId, notification);
}```
Thank you for help.
android above oreo will not show the notification in the foreground. You need to show it in the alert dialog
I have written an application, and in this application I can send a notification to users. In the first version, there were no problems. Then I made revisions with the same key, and I began experiencing problems.
Some devices no longer receive any notification, and one of these devices is my device. Later, I discovered that my device and others are no longer accepting any notification from GCM service, even though I put the new version of my app with GCM along with the new key or any app has GCM.
This problem has been reported to me by others who have updated to the new version of my app . But some users who updated the application works with them without any problems. I mean for some users, the app continues to work correctly.
when I run SuperVPN app all notifications delivered !
so two devices connected to same router
first one get notifications normally
other one not receiving without SuperVPN
manifist.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.labyb.englishwordeachday"
android:versionCode="2"
android:versionName="2.0.0" >
<uses-sdk android:minSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<permission
android:name="com.labyb.englishwordeachday.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.labyb.englishwordeachday.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.labyb.englishwordeachday.WordActivity"
android:label="#string/app_name"
android:parentActivityName=".AllWordsActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.AddsActivity"
android:label="#string/title_activity_adds"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.AllWordsActivity"
android:label="#string/title_activity_list"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.SplashActivity"
android:label="#string/title_activity_splash"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.labyb.englishwordeachday.SearchActivity"
android:label="#string/title_activity_search"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Holo.Light.Dialog" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.TranslateActivity"
android:label="#string/title_activity_translate"
android:theme="#android:style/Theme.Holo.Light.Dialog" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.TestActivity"
android:label="#string/title_activity_test_new" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.ReminderActivity"
android:label="#string/title_activity_reminder"
android:theme="#android:style/Theme.Holo.Light.Dialog" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.SetReminderActivity"
android:label="#string/title_activity_set_reminder"
android:theme="#android:style/Theme.Holo.Light.Dialog" >
</activity>
<receiver android:name="com.labyb.englishwordeachday.MyReceiver" >
<intent-filter>
<action android:name="com.labyb.englishwordeachday.mybroadcast" />
</intent-filter>
</receiver>
<activity
android:name="com.labyb.englishwordeachday.RemindersActivity"
android:label="#string/title_activity_reminders" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.SpeachActivity"
android:label="#string/title_activity_speach"
android:theme="#android:style/Theme.Holo.Light.Dialog" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.LevelsActivity"
android:label="#string/title_activity_levels" >
</activity>
<activity
android:name="com.labyb.englishwordeachday.WebActivity"
android:label="#string/title_activity_web" >
</activity>
<receiver
android:name="com.labyb.englishwordeachday.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.labyb.englishwordeachday" />
</intent-filter>
</receiver>
<service android:name="com.labyb.englishwordeachday.GcmIntentService" />
<receiver android:name=".StartUpBootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
</application>
</manifest>
GcmBroadcastReceiver.java
package com.labyb.englishwordeachday;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
GcmIntentService.java
package com.labyb.englishwordeachday;
import android.app.IntentService;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.labyb.englishwordeachday.classes.Adds;
import com.labyb.englishwordeachday.classes.DatabaseHandler;
public class GcmIntentService extends IntentService {
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
DatabaseHandler db;
static int counter = 0;
public GcmIntentService() {
super("GcmIntentService");
}
public static final String TAG = "GCM Demo";
#Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
sendNotification("Send error: " + extras.toString(), "Send error: " + extras.toString(), "Send error: " + extras.toString(), "Send error: " + extras.toString(), "Send error: "
+ extras.toString(), "Send error: " + extras.toString(), "Send error: " + extras.toString(), "Send error: " + extras.toString(), "Send error: " + extras.toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
sendNotification("Deleted messages on server: " + extras.toString(), "Deleted messages on server: " + extras.toString(), "Deleted messages on server: " + extras.toString(),
"Deleted messages on server: " + extras.toString(), "Deleted messages on server: " + extras.toString(), "Deleted messages on server: " + extras.toString(),
"Deleted messages on server: " + extras.toString(), "Deleted messages on server: " + extras.toString(), "Deleted messages on server: " + extras.toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// for (int i = 0; i < 5; i++) {
// Log.i(TAG, "Working... " + (i + 1) + "/5 # " +
// SystemClock.elapsedRealtime());
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {
// }
// }
Log.i(TAG, "Completed work # " + SystemClock.elapsedRealtime());
sendNotification(extras.get("word_id").toString(), extras.get("m1").toString(), extras.get("m2").toString(), extras.get("m3").toString(), extras.get("m4").toString(), extras.get("m5")
.toString(), extras.get("m6").toString(), extras.get("m7").toString(), extras.get("level").toString());
Log.i(TAG, "Received: " + extras.toString());
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
long[] vibraPattern = { 500, 500, 500, 500 };
private void sendNotification(String word_id, String m1, String m2, String m3, String m4, String m5, String m6, String m7, String level) {
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
if (m4.equals("v1")) {
} else if (m1.equals("newadd")) {
Intent myIntent = new Intent(this, AddsActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 1, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setContentTitle("قد يهمك ايضا")
.setStyle(new NotificationCompat.BigTextStyle().bigText(m2)).setAutoCancel(true).setTicker("قد يهمك ايضا").setVibrate(vibraPattern)
.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.ewed)).setContentText(m2);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
counter = counter + 1;
db = new DatabaseHandler(this);
db.addAdd(new Adds(m3, m2));// /hereeeeeeeeeeeeee
} else {
Intent i = new Intent(this, WordActivity.class);
i.putExtra("id", word_id);
PendingIntent contentIntent = PendingIntent.getActivity(this, 1, i, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setContentTitle(m1)
.setStyle(new NotificationCompat.BigTextStyle().bigText(m1)).setAutoCancel(true).setTicker("كلمة إنجليزية جديدة").setVibrate(vibraPattern)
.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.ewed)).setContentText(m2);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
counter = counter + 1;
db = new DatabaseHandler(this);
db.addNewWord(word_id, m1, m2, m3, m4, m5, m6, m7, level);// /hereeeeeeeeeeeeee
}
}
}
this is the sender code which is used to send message to gcm.
//sJSONObject obj = new JSONObject();
Sender sender = new Sender(GOOGLE_SERVER_KEY);
Message message = new Message.Builder().timeToLive(120)
.delayWhileIdle(true).addData(MESSAGE_KEY, userMessage).build();
System.out.println("regId: " + regId);
Object result = sender.send(message, regId, 5);
if (StringUtils.isEmpty(((Result) result).getErrorCodeName())) {
System.out.println("success");
System.out.println(result.toString());
}
else{
System.out.println(((Result) result).getErrorCodeName());
System.out.println(result.toString());
}
Manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.javapapers.android.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.javapapers.android.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".RegisterActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.javapapers.android.MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" >
</activity>
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.javapapers.android" />
</intent-filter>
</receiver>
<service android:name=".GCMNotificationIntentService" />
<!-- added by shashank -->
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
CCMBroadcastreciever:
package com.javapapers.android;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("GCMBroadcastReceiver", "OnReceive method");
System.out.println( "Broadcast receiver OnReceive method");
ComponentName comp = new ComponentName(context.getPackageName(),
GCMNotificationIntentService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
GCMNotificationIntentService:
package com.javapapers.android;
import android.app.IntentService;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.android.gms.gcm.GoogleCloudMessaging;
public class GCMNotificationIntentService extends IntentService {
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
public GCMNotificationIntentService() {
super("GcmIntentService");
}
public static final String TAG = "GCMNotificationIntentService";
#Override
protected void onHandleIntent(Intent intent) {
Log.d("GCMNotificationIntentService", "OnHandleIntent method");
System.out.println( "GCMNotificationIntentService OnHandleIntent method");
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR
.equals(messageType)) {
sendNotification("Send error: " + extras.toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
.equals(messageType)) {
sendNotification("Deleted messages on server: "
+ extras.toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE
.equals(messageType)) {
for (int i = 0; i < 3; i++) {
Log.i(TAG,
"Working... " + (i + 1) + "/5 # "
+ SystemClock.elapsedRealtime());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
}
Log.i(TAG, "Completed work # " + SystemClock.elapsedRealtime());
sendNotification("Message Received from Google GCM Server: "
+ extras.get(Config.MESSAGE_KEY));
Log.i(TAG, "Received: " + extras.toString());
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
private void sendNotification(String msg) {
Log.d(TAG, "Preparing to send notification...: " + msg);
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.gcm_cloud)
.setContentTitle("GCM Notification")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
Log.d(TAG, "Notification sent successfully.");
}
}
Output:
success
[ messageId=0:1414564158966354%31e4cc17f9fd7ecd ]
Still i'm not getting push notification on emulator. i have tried it on device as well. same problem occurs there as well.
I had a similar problem. I solved it using the classes in This GitHub example specifically noting the following:
Three 'services' and one 'receiver' together with all the permissions added in the github example.
AndroidManifest.xml
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.VIBRATE" />
<permission
android:name="<yourpackagename>.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="<yourpackagename>.permission.C2D_MESSAGE" />
<service
android:name=".utility.MyGcmRegistrationIntentService"
android:exported="false" >
</service>
<service
android:name=".utility.MyGcmListenerService"
android:exported="false" >
<intent-filter>
actionandroid:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter</service>
<service
android:name=".utility.MyInstanceIdListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="<com.example.yourpackagename>" />
</intent-filter>
</receiver>
The Receiver is implemented in the
ActivityMain.java:
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean sentToken = sharedPreferences.getBoolean(SENT_TOKEN_TO_SERVER, false);
if (sentToken) {
} else {
}
}
};
#Override
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
new IntentFilter("registrationComplete"));
}
#Override
protected void onPause() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver);
super.onPause();
}
You can basically use the other files just like they are:
MyGcmListenerService.java - The one where you can customize your notification icon and text.
MyInstanceIDListenerService.java
QuickstartPreferences.java
RegistrationIntentService.java