如何从我的主配置文件中的应用程序获取我的工作配置文件应用程序的启动意图?
这个问题针对 Android 工作.
This question targets Android for work.
我按照这个指南编写了一个包含 DevicePolicyController 的应用.控制器为我的 Android 设备创建托管配置文件.
I have written an app including a DevicePolicyController following this guide. The controller creates a managed profile for my Android device.
我在该配置文件中添加了一个名为 FooApp 的应用.现在我可以在启动器中看到两个 FooApp 图标,一个有工作徽章,一个没有.
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.
我还有一个应用 BarApp,它只在主配置文件中.如何在 BarApp 中获取 FooApp 工作版的启动意图?(从 BarApp 内启动 FooApp 的工作版本)
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)
我无法使用 CrossProfileApps,因为我在使用 API23.
I can't use CrossProfileApps as I am on API 23.
如果没有用户同意,我提出的解决方案是不可能发生的.也许未来会有更好的.但这是我的:
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:
我在 FooApp 的 Manifest 中为 FooActivity 添加了以下意图过滤器.
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>
然后我为我的工作配置文件添加了一个 crossProfileIntentfilter(将以下代码放在当前在工作配置文件中运行的配置文件管理应用程序中).
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);
最后,当我想在工作配置文件中启动应用程序时,我会从 BarApp 触发 ACTION_HOMELAUNCHER
意图,然后用户可以选择,他是否想要启动FooApp的工作配置文件版本或普通版本.
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.
请随时改进此答案.