[英]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 但是,当我们使用getPackageManager()
,代码将崩溃,
error = Unfortunately, TheAppName instant app has stopped. 错误=不幸的是,TheAppName即时应用已停止。
Nothing is printed in Logcat. 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 安卓版本:6.0.1
Update 更新
The reason for not printing Logs is debugger was not attached to the App . 不打印日志的原因是未将调试器附加到应用程序 。 The logs from adb console shows: 来自adb控制台的日志显示:
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 App Documentation 3.15。 Instant Apps device implementations MUST satisfy the following requirements: Instant Apps设备实施必须满足以下要求:
android:visibleToInstantApps
目标通过android:visibleToInstantApps
显式公开 to make visible to instant app and it support from Android 8.0 使即时应用程序可见,并且支持Android 8.0
if we have to check isInstantApp
from installed app
如果我们必须从installed app
检查isInstantApp
isInstantApp(packageName)
will return a valid value( false
) if the caller is able to see the instant app. 如果调用者能够看到即时应用程序,则isInstantApp(packageName)
将返回有效值( false
)。 The caller can see the instant app in the following scenarios: 呼叫者可以在以下情况下查看即时应用程序:
ACCESS_INSTANT_APPS
拥有权限ACCESS_INSTANT_APPS
VIEW_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... ] 绑定到服务,开始活动等... ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.