3

I got an android demo named BasicManagedProfile which implements some new features about device policy manager.

Now I have a question about how to get the other package names when application in managed profile. For example, the demo shows the chrome and calculators name string to make 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 like dialer and contact.

I tried to use getInstalledPackages() or queryIntentActivities() but failed.

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 the queryIntentActivities() can not return the right list of applications. Please give me some suggestion about these.

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Darkmoon
  • 31
  • 3

3 Answers3

1

Not a solution but a tip.

By adding the flag GET_UNINSTALLED_PACKAGES you can retrieve a list containing apps from primary account:

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

After uninstalling an app with no persistent data in the primary account, it is not returned by this method. So it do part of the job.

However, the method may return applications that are really uninstalled too.

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

Hartok
  • 2,147
  • 20
  • 37
0

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

I made a simple demo.The link below: https://github.com/guiyu/DevicePolicyTest.git

Darkmoon
  • 31
  • 3
  • I have a similar problem. The link to the demo does not work anymore. Can you explain how you solved it? – kahlk Dec 16 '20 at 11:03
-1

You can try this to get the package names of all the application 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 holds the Context, you can directly call getPackageManager() method inside activity without using Context.

Akhil
  • 829
  • 1
  • 11
  • 26
  • I'm so sorry.This method is same as "List packageInfoList = context.getPackageManager().getInstalledPackages(0);".The result also not include the taget packagename like "com.google.android.dialer" – Darkmoon Dec 06 '14 at 10:35