How do I get a list of package information from the master account when the app is in a managed profile?

I have an Android demo called BasicManagedProfile that implements some of the new Device Policy Manager functionality.

Now I have a question on how to get the other package names when the application is in a managed profile. For example, the demo shows a chrome name string and a calculator for making presentations.

/**
 * 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";

      

But I want to know how to get others to use the dialer and contact.

I tried using getInstalledPackages()

or queryIntentActivities()

but couldn't.

By the way, I use the method addCrossProfileIntentFilter()

like this:

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);

      

But queryIntentActivities()

cannot return the correct list of applications. Please give me some suggestion about this.

+3


source to share


3 answers


Not a solution, but a hint.

By adding a flag GET_UNINSTALLED_PACKAGES

, you can get a list containing apps from the main account:

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

      



After uninstalling an app without persistent data in the master account, it is not returned by this method. So this is part of the job.

However, the method can also return applications that are indeed deleted.

If the GET_UNINSTALLED_PACKAGES flag is set, and if the package is not found in the list of installed applications, the application information is retrieved from the list of deleted applications (including installed applications, as well as applications with a data directory, i.e. applications that were removed with the DONT_DELETE_DATA flag set).

+1


source


I have solved this problem. The method is to pass data from the admin profile. I used intent, file or contentprovider to load data.



I've made a simple demo. Link below: https://github.com/guiyu/DevicePolicyTest.git

0


source


You can try this to get package names for all apps on your device.

List<ApplicationInfo> pkgAppsList = mContext.getPackageManager()
            .getInstalledApplications(
                    PackageManager.GET_META_DATA); 
for (ApplicationInfo appInfo : appsList) {
// you can get package name by appInfo.packageName
Log.d("Package Name",": " + appInfo.packageName);
}

      

here mContext contains context, you can directly call getPackageManager () method inside activity without using Context.

-1


source







All Articles