3

This question targets Android for work.

I have written an app including a DevicePolicyController following this guide. The controller creates a managed profile for my Android device.

I added an app to that profile which is called FooApp. Now I can see two icons of FooApp in my launcher, one with work badge and one without.

I also have an app BarApp, which is only in the primary profile. How do I get the launch intent for the work version of FooApp in BarApp? (Start the work version of FooApp from within BarApp)

I can't use CrossProfileApps as I am on API 23.

Xerusial
  • 525
  • 1
  • 5
  • 17
  • What do you mean by "the work version of FooApp"? What is the difference between the 2 versions of the app? – David Wasser Jun 07 '19 at 12:39
  • The work version has got a different UID and data scope. See: https://source.android.com/devices/tech/admin/managed-profiles#settings – Xerusial Jun 07 '19 at 14:07
  • I just managed to launch the work version by adding an custom intent and intent filter to **FooApp** and adding a crossprofileintentfilter for that very intent to my devicepolicycontroller. Then i fire the intent from **BarApp**. The user can now decide on his own to use the work version. But using the work version by default would be better. – Xerusial Jun 07 '19 at 14:10

1 Answers1

1

The Solution I came up with cannot happen without the users consent. Maybe there will be a better one in the future. But here is mine:

I added the following intent filter for FooActivity in the Manifest of FooApp.

<intent-filter>
    <action android:name="com.example.FooApp.ACTION_HOMELAUNCHER"/>
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Then I added a crossProfileIntentfilter for my work profile (put the following code in the profile administration app currently running in the work profile).

DevicePolicyManager manager =
            (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName componentName = BasicDeviceAdminReceiver.getComponentName(context);
IntentFilter filterin = new IntentFilter("com.example.FooApp.ACTION_HOMELAUNCHER");
manager.addCrossProfileIntentFilter(componentName, filterin, DevicePolicyManager.FLAG_MANAGED_CAN_ACCESS_PARENT);

In the end, when I want to launch the App in the work profile, I fire the ACTION_HOMELAUNCHER intent from BarApp and then the user can select, whether he wants to lauch the work profile version or the normal version of FooApp.

Feel free to improve upon this answer.

Xerusial
  • 525
  • 1
  • 5
  • 17