我想在实现 Parcelable 的自定义类型的额外数据中发送带有意图的广播消息。
详细信息:我想在 HS 上创建快捷方式但是系统不接受我的自定义命令类型的对象,错误消息:android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.solvek.ussdfaster.entities.Command
当用户单击快捷方式时,此对象将被传递回我的应用程序。
Intent shortcutIntent = new Intent(this, FormActivity.class);
shortcutIntent.putExtra("command", command); // Note - commmand is my custom object
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, command.getTitle());
Parcelable iconResource = Intent
.ShortcutIconResource
.fromContext(this, R.drawable.ic_launcher);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);