问题描述
我要创建需要不同的表现,如果它在工作配置文件中运行的应用程序。
I'm creating an app that needs to behave differently if it's running in the work profile.
有任何可能性,知道吗?
There is any possibility to know that?
该文件有没有什么办法,我已经尝试添加一个限制,即仅可在工作形象和它的作品,但我需要无需管理员的任何操作的解决方案。
The documentation has nothing about it and I already tried to add a restriction that is only available in the work profile and it works, but I need a solution without any action from the administrator.
Android for Work的信息:
Android for work information:http://www.android.com/work/
Android for Work的文档:
Android for work documentation:https://developer.android.com/training/enterprise/index.html
推荐答案
我找到了解决办法:
如果isProfileOwnerApp一个包名返回true,则意味着您的应用程序(贴牌)的工作配置文件中运行。
如果您的应用程序在正常模式下运行(没有徽章)isProfileOwnerApp返回所有管理员假的,即使是有工作的个人资料。
I found a solution :if isProfileOwnerApp return true for one package name, it means that your app (badged) is running on work profile.if your app is running in normal mode (no badge) isProfileOwnerApp return false for all admins even if there is a Work profile.
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
List<ComponentName> activeAdmins = devicePolicyManager.getActiveAdmins();
if (activeAdmins != null){
for (ComponentName admin : activeAdmins){
String packageName= admin.getPackageName();
Log.d(TAG, "admin:"+packageName);
Log.d(TAG, "profile:"+ devicePolicyManager.isProfileOwnerApp(packageName));
Log.d(TAG, "device:"+ devicePolicyManager.isDeviceOwnerApp(packageName));
}
}
这篇关于的Android for Work - 如何检查是否我的应用程序在工作配置文件中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!