I want to add home screen shortcuts to individual chat rooms, in my app. Here's my code to do so:
Intent roomIntent = roomIntent(room).putExtra("shortcut", true);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, roomIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, room.name);
Parcelable resource = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, resource);
setResult(RESULT_OK, intent);
finish();
When I go to add the shortcut to my home screen, I get a Force Close, not on my own process, but on com.android.acore(!). I've run the debugger and verified that my code gets executed all the way to the call to finish().
If I do this instead for the EXTRA_SHORTCUT_ICON:
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, R.drawable.icon);
It works fine and places the shortcut, and the shortcut behaves correctly -- but of course the shortcut has the stock Android icon, not mine, since this isn't the proper way to specify the icon.
When I look at the source code of other apps that have done this, and at the one example of it in the official Android reference area, my code looks identical. My icon's a standard 48x48 png that I use for the app's main icon, without problems. I've verified this problem on an emulator running stock 1.6, haven't tested other versions.
I have no idea what I'm doing wrong. Any ideas?