Java 将意图转换为字符串,反之亦然
我打算开始这样的快捷方式活动:Java 将意图转换为字符串,反之亦然,java,android,sqlite,android-intent,Java,Android,Sqlite,Android Intent,我打算开始这样的快捷方式活动: startActivity((Intent) shortcut_intent.getExtras().get(Intent.EXTRA_SHORTCUT_INTENT)); 我需要将快捷方式转换为字符串以将其保存在sqlite db中。我试了这么久,但没有成功。现在我站在这里: 将意图转换为字符串: String uri_string = mIntent_shortcut_intent.toUri(0); Intent intent = new Intent(
startActivity((Intent) shortcut_intent.getExtras().get(Intent.EXTRA_SHORTCUT_INTENT));
我需要将快捷方式转换为字符串以将其保存在sqlite db中。我试了这么久,但没有成功。现在我站在这里:
将意图转换为字符串:
String uri_string = mIntent_shortcut_intent.toUri(0);
Intent intent = new Intent();
intent.putExtra("android.intent.extra.shortcut.INTENT", Uri.parse(uri_string));
创建新的意图:
String uri_string = mIntent_shortcut_intent.toUri(0);
Intent intent = new Intent();
intent.putExtra("android.intent.extra.shortcut.INTENT", Uri.parse(uri_string));
并从uri解析额外内容:
String uri_string = mIntent_shortcut_intent.toUri(0);
Intent intent = new Intent();
intent.putExtra("android.intent.extra.shortcut.INTENT", Uri.parse(uri_string));
不工作/应用程序崩溃;(
有人能帮我吗?或者告诉我在sqlite db中保存一个意图持久化的替代方法
提前thx
更新:
String uri_string = mIntent_shortcut_intent.toUri(0);
Intent intent = new Intent();
intent.putExtra("android.intent.extra.shortcut.INTENT", Uri.parse(uri_string));
正如pskink所建议的那样,拆封多余的包裹,反之亦然,我做了以下工作:
Bundle bundle=shortcutIntent.getExtras();
Parcel parcel=Parcel.obtain();
bundle.writeToParcel(parcel, 0);
byte[] byt=parcel.marshall();
Bundle newBundle=new Bundle();
Parcel newParcel=Parcel.obtain();
newParcel.unmarshall(byt, 0, byt.length);
bundle.readFromParcel(newParcel);
Intent intent=new Intent();
intent.putExtras(newBundle);
startActivity((Intent) intent.getExtras().get(Intent.EXTRA_SHORTCUT_INTENT));
新绑定的外观与原始绑定的外观不完全相同,并且仍在崩溃。因此,仍然存在一些问题….只是为了完成此线程/帮助其他人 pskink帮助我找到了以下解决方案:
Bundle bundle = shortcutIntent.getExtras();
Parcel parcel = Parcel.obtain();
bundle.writeToParcel(parcel, 0);
byte[] byt = parcel.marshall();
String s = Base64.encodeToString(byt, 0, byt.length, 0); //store this string to sqlite
byte[] newByt = Base64.decode(s, 0);
Bundle newBundle = new Bundle();
Parcel newParcel = Parcel.obtain();
newParcel.unmarshall(newByt, 0, newByt.length);
newParcel.setDataPosition(0);
newBundle.readFromParcel(newParcel);
Intent intent = new Intent();
intent.putExtras(newBundle);
MainActivity.getContext().startActivity((Intent)intent.getExtras().get(Intent.EXTRA_SHORTCUT_INTENT));
再次非常感谢你!你试过这么做吗
String sIntent = intent.toString();
若要将意图转换为字符串?是否可以发布日志堆栈?使用
string action=intent.getAction();
并将其存储到sqlite。@Ketan Ahir:在我的快捷方式intent中,action始终为“null”。只有“Extras”有值,所以我认为它没有用……使用此构造函数创建intent i=new intent(“您的操作”);intent intent=intent.parse(uri_字符串)