4

We have encountered a strange problem in our app that happens mainly when our app is updated on the user's device when a notification is "live" on his notifications list.

When the user clicks on the notification - we get an exception :

android.app.RemoteServiceException
Bad notification posted from package ... : Couldn't create icon: StatusBarIcon(pkg=.....=0 id=0x0 level=0 visible=true num=0 )

It seems that since the app was updated - the resourceId has changed and is no longer legal, thus the exception (more info here : How to fix: android.app.RemoteServiceException: Bad notification posted from package *: Couldn't create icon: StatusBarIcon)

Currently, as a temporary solution, we set up a broadcast receiver that gets triggered after an update of the app and cancels any existing notifications.

However - a more elegant solution would be to have a resource like R.drawable.ic_launcher always get the same numeric value (identifier) when compiling so it would stay the same even after upgrades.

Is there a way to do this?

Community
  • 1
  • 1
FunkSoulBrother
  • 2,057
  • 18
  • 27
  • 1
    As per this [comment](https://code.google.com/p/android/issues/detail?id=82121#c17) by a google developer, you can use `DexGuard` to keep the resources. But you need to buy `DexGuard`. – Prerak Sola Jul 19 '16 at 11:52
  • @PrerakSola The comment you're referencing isn't by a "google developer", just an app developer like any other. Also he doesn't say that you can fix this with DexGuard, but that if you are using DexGuard you might need to tell the tool to keep this specific resource. DexGuard does not have any options for pinning a resource to a specific ID, which means the problem with refreshing notifications after an update still exist. – Thorbear Oct 06 '16 at 08:36

1 Answers1

0

Create a public.xml in your res/values folder. The ids for each resource can be fixed if it is written correctly in public.xml. The format is as following:

...
<public type="drawable" name="notification_icon" id="0x7f0200ab" />
...

Note that Android has naming rules for these ids. You may google for details.

Or you can decompile the apk file and get a public.xml from res/values. This file includes all the resources and you can just copy what you want.

More on ids fixing.

Community
  • 1
  • 1
thundertrick
  • 1,634
  • 1
  • 17
  • 22