gpt4 book ai didi

android - 如何将字符串值从一个应用程序传递到android中的另一个应用程序

转载 作者:搜寻专家 更新时间:2023-11-01 08:30:40 25 4
gpt4 key购买 nike

这是我的应用 A 并且有一个字符串值 "Hello"。我想将这个字符串值发送到应用程序 B。

String mystring = "Hello";
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.test");
if (launchIntent != null) {
launchIntent.putExtra("success", mystring);
startActivity(launchIntent);
}

这是我的应用 B

Bundle b = getIntent().getExtras();
if (b != null) {
String myString = b.getString("success");
Toast.makeText(MainActivity.this, "" + myString, Toast.LENGTH_SHORT).show();
}

在接收“app B”时,myString 被接收为 null

最佳答案

在应用程序 B 的 list 上,

您需要声明类别为 DEFAULT 的 Intent 过滤器和 Action = com.your_app_package_name.your_app_name.ActivtiyAlpha

然后你需要设置action在你的Intent为应用程序 A 启动该 Activity 并发送额外的数据。

Intent i = new Intent("com.your_app_package_name.your_app_name.ActivtiyAlpha");
i.putExtra("KEY_DATA_EXTRA_FROM_ACTV_B", myString);
// add extras to any other data you want to send to b
launchIntent.putExtra("success",mystring);
startActivity(launchIntent);

结帐 detailed Answer here

关于android - 如何将字符串值从一个应用程序传递到android中的另一个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41185090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com