Android gcm push notifications accidentally open app
We have a strange bug in our application. Our app is designed to receive GCM push notifications and open the app for a specific action based on the notification payload when the notification is clicked. This all works great, except that on rare occasions (since I've activated 500+ push notifications and only saw it happening twice), our app will open seemingly without user intervention. It seems like something is triggering a notification in the notification bar. Has anyone experienced something similar or have any idea what might be causing this? I searched quite a bit on Google and StackOverflow but I only found one question about similar behavior with no answers, which can be seen herehttps://stackoverflow.com/questions/19112479/push-notification-is-opening-app-directly
I have included BroadcastReceiver, IntentService and intent filters from the manifest below.
BroadcastReceiver:
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);
}
}
IntentService:
public class GCMIntentService extends IntentService {
private static final int NOTIFICATION_ID = 100;
public GCMIntentService() {
super("GcmIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
if (!extras.isEmpty()) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(gcm.getMessageType(intent)))
sendNotification(extras.getString(GlooIntents.GLOO_URL), extras.getString(GlooIntents.ALERT));
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
private void sendNotification(String url, String message) {
long when = System.currentTimeMillis();
Intent notificationIntent = new Intent(this, SplashActivity.class);
notificationIntent.putExtra("nextPath", url);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.drawable.ic_home);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_home));
builder.setWhen(when);
builder.setContentIntent(pendingIntent);
builder.setContentTitle(getString(R.string.app_name_replace_me));
builder.setContentText(message);
builder.setAutoCancel(true);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
notificationManager.notify(NOTIFICATION_ID, builder.getNotification());
}
}
manifesto
<activity
android:name=".GroupActivity"
android:label="@string/group"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<data
android:host="app"
android:pathPattern="/groups/.*"
android:scheme="gloo" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
source to share
No one has answered this question yet
Check out similar questions: