0

I have one application "Master" installed on phone. Is it possible to access resource from other app "Slave" as instant app ?

I know that it's possible between 2 installed apps using :

Resources resources = getPackageManager().getResourcesForApplication(packageName);
String slaveAppName = resources.getString(resources.getIdentifier("app_name", "string", packageName));

Thx

L.E :

I also try to send data from the instant app to the installed application ( reverse from above ) using :

Intent intent = new Intent("com.test.MainActivity");
intent.putExtra("data","data string");
startActivity(intent);

on the installed app i have in AndroidManifest :

 <intent-filter>
    <action android:name="com.text.MainActivity" />
    <category android:name="android.intent.category.DEFAULT" />
 </intent-filter>

All good when i try to send data as installed app... but once i build the instant app.....it crash with :

Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.text.MainActivity (has extras) }

L.E (2)

i also try just for testing to find out how many apps are installed on the phone with the instant app build using :

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

This was a test just to find out if the instant app build can "touch" the local phone settings. And it works

Prags
  • 2,457
  • 2
  • 21
  • 38
BejanCorneliu
  • 65
  • 3
  • 13
  • Can you add any details like: code used, error problem encountered? [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask), [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) Show the community what you have tried. – ReyAnthonyRenacia Apr 20 '18 at 11:03
  • I did try like in the example before. That way works when both app are installed on the phone. But with one app installed...lets call it "master" and other instant app called "slave" with the code above did not work. The "slave" app was not found using the app package name. – BejanCorneliu Apr 20 '18 at 16:06
  • With Launcher API you can check if instant app is available on device https://developers.google.com/android/reference/com/google/android/gms/instantapps/Launcher. And with LaunchData API you can get a metadata from instant app if it exists for the URL https://developers.google.com/android/reference/com/google/android/gms/instantapps/LaunchData. Refer to code snippet at https://stackoverflow.com/a/49703031/8320998 – Julia K Apr 28 '18 at 00:01

1 Answers1

1

Instant app can access an installed app’s resources with

Resources resources = getPackageManager().getResourcesForApplication(packageName);  String slaveAppName = resources.getString(resources.getIdentifier("app_name", "string", packageName));

code when installable app is visible to instant.

Add the following to your installed app to make it visible for instant apps:

  • For Android O+: android:visibleToInstantApps="true" to the component
  • For Android pre-O: <meta-data android:name="instantapps.clients.allowed" android:value="true"/> to <application>

More details at How to expose component from installed app to be visible to instant app?

To get instant app metadata from the installed app use LaunchData API

As for sending data from instant to installed app, on pre-O devices instant app crashes with java.lang.SecurityException: Not allowed to start activity Intent, this suggests that it’s not supported in Instant Apps, see Not able to launch Gallery from Android Instant app.

Prags
  • 2,457
  • 2
  • 21
  • 38
Julia K
  • 561
  • 5
  • 11