简体   繁体   English

如何从即时应用程序中列出已安装的应用程序?

[英]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

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 App Documentation 3.15。 Instant Apps device implementations MUST satisfy the following requirements: Instant Apps设备实施必须满足以下要求:

  • The target is explicitly exposed with 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: 呼叫者可以在以下情况下查看即时应用程序:

  • It is the instant app 这是即时应用
  • Is part of the system 是系统的一部分
  • Holds the permission ACCESS_INSTANT_APPS 拥有权限ACCESS_INSTANT_APPS
  • Is the system defined, default launcher holding the permission 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... ] 绑定到服务,开始活动等... ]

    MoreInfo 更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取已安装的即时通讯应用程序列表? - how to get list of installed instant messenger apps? Android即时应用:如何调试即时应用? - Android Instant Apps: How to debug an instant app? 如何将已安装应用程序中的组件公开给即时应用程序? - How to expose component from installed app to be visible to instant app? 如何将数据从即时应用还原到已安装的应用? - How can I restore data from instant app to installed app? Android即时应用:如何在部署后测试即时应用? - Android Instant Apps : How to test an Instant app after deploying? 如何列出另一个应用程序中所有已安装的Android应用程序的权限 - How do you list the permissions for all installed Android Apps from another App 如何在android免安装应用程序中存储数据并在已安装的应用程序中恢复数据 - How to store data in android instant app and restore it in installed app Android:如何从已安装的用户应用程序中创建复选框列表 - Android: how to do a checkbox list from installed user apps 在已安装的应用程序列表中找不到该应用程序 - The app wasn't found in the list of installed apps 已安装的应用程序检测:如何根据已安装的应用程序扫描和列出附近的电话 - Installed App Detection: how can i scan and list phones in the vicinity based on apps installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM