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
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?
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:
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:
ACCESS_INSTANT_APPS
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... ]
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.