简体   繁体   中英

How to list installed apps from instant app?

As per documentation ,

The instant apps are restricted to discover the list of installed apps on the device, unless the installed apps have made themselves discoverable to instant apps.

There is also a way to make our app discoverable to instant apps.

But when we use getPackageManager() , the code crashes with the

error = Unfortunately, TheAppName instant app has stopped.

Nothing is printed in Logcat. Following is printed on the Debug console,

02/10 22:57:27: Launching instantapp
Side loading instant app.
Side loading instant app.
Launching deeplink: https://myapp.mycompany.com/example.

$ adb shell setprop log.tag.AppIndexApi VERBOSE
$ adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d https://myapp.mycompany.com/example -n "com.google.android.instantapps.supervisor/.UrlHandler"
Waiting for application to come online: com.mycompany.myapp.instantappscanner.test | com.mycompany.myapp.instantappscanner
Waiting for application to come online: com.mycompany.myapp.instantappscanner.test | com.mycompany.myapp.instantappscanner
Waiting for application to come online: com.mycompany.myapp.instantappscanner.test | com.mycompany.myapp.instantappscanner
Could not connect to remote process. Aborting debug session.

Code:

PackageManager packageManager = getPackageManager();
List<ApplicationInfo> packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo packageInfo : packages) {
    Log.d(TAG, "Installed package :" + packageInfo.packageName);
    Log.d(TAG, "Source dir : " + packageInfo.sourceDir);
}

Android Version : 6.0.1

Update

The reason for not printing Logs is debugger was not attached to the App . The logs from adb console shows:

02-11 21:06:56.347: E/AndroidRuntime(18033): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.myapp.aninstantapp/com.mycompany.myapp.aninstantapp.feature.MainActivity}: java.lang.SecurityException: Method class android.content.pm.IPackageManager$Stub$Proxy.getInstalledApplications[int, int] not available to instant apps

Full stack trace

Stack trace prints that the call is not allowed from an instant app, but what if few apps made themselves discoverable to instant apps ? Rather than throwing exception method call should return a partial list of apps containing only apps which made themselves discoverable to instant apps?


Short Question

Need help executing following code from an instant app.

List<ApplicationInfo> packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);

It throws exception,

SecurityException: IPackageManager$Stub$Proxy.getInstalledApplications[int, int] not available to instant apps

It should not throw an exception because one can have few apps which made themselves discoverable to instant apps, as supported by documentation (above).

With Reference Instant App Documentation 3.15. Instant Apps device implementations MUST satisfy the following requirements:

  • The target is explicitly exposed with android:visibleToInstantApps

to make visible to instant app and it support from Android 8.0

if we have to check isInstantApp from installed app

isInstantApp(packageName) will return a valid value( false ) if the caller is able to see the instant app. The caller can see the instant app in the following scenarios:

  • It is the instant app
  • Is part of the system
  • Holds the permission ACCESS_INSTANT_APPS
  • Is the system defined, default launcher holding the permission VIEW_INSTANT_APPS
  • Is a regular app that the instant app has established a connection to an exposed component [ eg. bound to a service, started an activity, etc... ]

    MoreInfo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM