gttn gttn - 1 year ago 274
Android Question

NotificationManager failing to display notification with "notify: id corrupted: sent 1, got back 0" warning

I've had a problem with NotificationManager in my app for the past couple of days and I don't seem to be getting closer to solving it.

I have a very simple service which does not do anything at the moment. It is just supposed to display notification:

public class UpdateService extends Service {
private static final String TAG = "UpdateService";
private static int NOTIFICATION_ID = 1;
private UpdateServiceBinder binder = new UpdateServiceBinder();

@Override
public void onCreate() {
Log.i(TAG, "Service created");
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "Service started");

sendNotification(100);

return Service.START_NOT_STICKY;
}

private void sendNotification(int updatedItems) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.icon)
.setContentTitle("Sync")
.setContentText("Updated " + updatedItems);

Intent resultIntent = new Intent(getBaseContext(), MainActivity.class);

TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);

PendingIntent resultPendindIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

builder.setContentIntent(resultPendindIntent);

NotificationManager manager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(NOTIFICATION_ID, builder.build());
}

@Override
public IBinder onBind(Intent intent) {
return binder;
}

@Override
public boolean onUnbind(Intent intent) {
return true;
}

public class UpdateServiceBinder extends Binder {
public UpdateService getService() {
return UpdateService.this;
}
}


}

Unfortunately, when the service is started and the notification is supposed to be displayed nothing happens. The service is definitely started according to log messages. At the same time there is warning from NotificationManager:


11-30 23:24:34.620: I/UpdateService(28356): Service created

11-30 23:24:34.800: I/UpdateService(28356): Service started

11-30 23:24:34.808: W/NotificationManager(28356): notify: id
corrupted: sent 1, got back 0


I tried using different numbers than 1 but it did not help. I am not sure what to make out of it. The code I'm using comes from the Android documentation on service in here and notifications in here. When I isolate the code in separate clean app which is setup in similar way to the one I'm working on notification is displayed correctly. Has anybody had this problem before or has any ideas?

Any help appreciated.
Thanks!

Answer Source

I found a solution to this problem. I had to change the package name from com.gttn.sample to com.gttn.sample2. Not really sure why I had to do it but the notifications show properly and the warning disappeared.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download