【问题标题】:Application access resources from instant application (other)来自即时应用程序(其他)的应用程序访问资源
【发布时间】:2018-04-19 17:34:49
【问题描述】:

我在手机上安装了一个应用程序“Master”。是否可以从其他应用“Slave”作为即时应用访问资源?

我知道在 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);

在我在 AndroidManifest 中安装的应用程序上:

 <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());

这是一项测试,旨在确定即时应用构建是否可以“触摸”本地电话设置。它有效

【问题讨论】:

标签: java android android-resources android-instant-apps


【解决方案1】:

免安装应用可以通过

访问已安装应用的资源
Resources resources = getPackageManager().getResourcesForApplication(packageName);  String slaveAppName = resources.getString(resources.getIdentifier("app_name", "string", packageName));

当可安装应用对即时可见时的代码。

将以下内容添加到已安装的应用中,使其对免安装应用可见:

  • 对于 Android O+:android:visibleToInstantApps="true" 到 组件
  • 对于Android pre-O:&lt;meta-data android:name="instantapps.clients.allowed" android:value="true"/&gt;&lt;application&gt;

更多详情How to expose component from installed app to be visible to instant app?

要从已安装的应用中获取即时应用元数据,请使用 LaunchData API

关于将数据从即时应用程序发送到已安装的应用程序,在预 O 设备上即时应用程序崩溃与 java.lang.SecurityException: Not allowed to start activity Intent,这表明 Instant Apps 不支持它,请参阅 Not able to launch Gallery from Android Instant app

【讨论】:

    猜你喜欢
    • 2019-12-31
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    相关资源
    最近更新 更多