android - managed profile申请时如何获取主账号的包裹信息列表?

标签 android android-5.0-lollipop device-policy-manager

我有一个名为 BasicManagedProfile 的安卓演示它实现了有关设备策略管理器的一些新功能。

现在我有一个问题,关于在托管配置文件中应用程序时如何获取其他包名称。例如,演示显示 chrome 和计算器名称字符串来进行演示。

/**
 * Package name of calculator
 */
private static final String PACKAGE_NAME_CALCULATOR = "com.android.calculator2";

/**
 * Package name of Chrome
 */
private static final String PACKAGE_NAME_CHROME = "com.android.chrome";

但我想知道如何获得其他人,如拨号器和联系人。

我尝试使用 getInstalledPackages()queryIntentActivities() 但失败了。

顺便说一句,我像这样使用方法addCrossProfileIntentFilter():

IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN); filter.addCategory(Intent.CATEGORY_LAUNCHER);

MyActivity.deviceManager.addCrossProfileIntentFilter(MyReceiver.getComponentName(context), filter, FLAG_MANAGED_CAN_ACCESS_PARENT | FLAG_PARENT_CAN_ACCESS_MANAGED);

但是 queryIntentActivities() 无法返回正确的应用程序列表。 请给我一些关于这些的建议。

最佳答案

不是解决方案,而是提示。

通过添加标志 GET_UNINSTALLED_PACKAGES,您可以从主帐户检索包含应用程序的列表:

mContext.getPackageManager()
            .getInstalledApplications(
                    PackageManager.GET_UNINSTALLED_PACKAGES);

卸载主账号没有持久化数据的应用后,该方法不返回。所以它完成了部分工作。

但是,该方法也可能返回真正卸载的应用程序。

If flag GET_UNINSTALLED_PACKAGES is set and if the package is not found in the list of installed applications, the application information is retrieved from the list of uninstalled applications(which includes installed applications as well as applications with data directory ie applications which had been deleted with DONT_DELETE_DATA flag set).

关于android - managed profile申请时如何获取主账号的包裹信息列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27311251/

相关文章:

java - 如何以编程方式为应用程序设置锁定或 pin

java.lang.SecurityException : No active admin owned by uid 10047 for policy #4 on wipe data

android - 源集 Android Studio

javascript - 如何在 Titanium Appcelerator 应用程序中保存持久值

android - Android Lollipop 上的持久化应用程序

android - Lollipop EditBox 样式

android-5.0-lollipop - 如何取消配置设备以设置设备所有者?

android - 如何从 developer.android 网站导入示例?

android - 使用 KSoap 从 Android 连接到 Web 服务

android - RecyclerView notifyItemInserted IllegalStateException