我在手机上安装了一个应用程序"Master"。是否可以从其他应用程序"奴隶"访问资源作为即时应用程序?
我知道在 2 个已安装的应用程序之间可以使用:
Resources resources = getPackageManager().getResourcesForApplication(packageName);
String slaveAppName = resources.getString(resources.getIdentifier("app_name", "string", packageName));
感谢
L.E :
我还尝试使用以下方法将数据从即时应用程序发送到已安装的应用程序(从上面反向(:
Intent intent = new Intent("com.test.MainActivity");
intent.putExtra("data","data string");
startActivity(intent);
在我在安卓清单中安装的应用程序上:
<intent-filter>
<action android:name="com.text.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
当我尝试将数据作为已安装的应用程序发送时,一切都很好......但是一旦我构建了即时应用程序.....它崩溃与:
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.text.MainActivity (has extras) }
L.E (2(
我还尝试进行测试,以找出手机上安装了多少个应用程序,并使用免安装应用程序构建使用以下方法:
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> pkgAppsList =
this.getPackageManager().queryIntentActivities( mainIntent, 0);
Log.d("log","installed apps : "+pkgAppsList.size());
这是一项测试,只是为了了解免安装应用构建是否可以"接触"本地手机设置。它有效
免安装应用可以使用以下方法访问已安装应用的资源
Resources resources = getPackageManager().getResourcesForApplication(packageName); String slaveAppName = resources.getString(resources.getIdentifier("app_name", "string", packageName));
可安装应用时的代码对即时可见。
将以下内容添加到已安装的应用中,使其对免安装应用可见:
- 对于安卓 O+:
android:visibleToInstantApps="true"
元件 - 对于安卓预O:
<meta-data android:name="instantapps.clients.allowed" android:value="true"/>
到<application>
有关更多详细信息,请参阅如何将已安装应用程序中的组件公开为对免安装应用程序可见?
要从已安装的应用程序获取即时应用程序元数据,请使用启动数据 API
至于将数据从即时发送到已安装的应用程序,在pre-O设备上,即时应用程序崩溃 java.lang.SecurityException: Not allowed to start activity Intent
,这表明免安装应用不支持它,请参阅无法从 Android 免安装应用启动图库。