使用CrossProfileApps在托管配置文件上运行应用程序

huangapple go评论85阅读模式
英文:

Use CrossProfileApps to run app on managed profile

问题

我正在开发一个应用程序,需要从我的智能手机的工作配置文件中运行。我已经阅读了谷歌关于工作配置文件的文档,特别是关于CrossProfileApps类的部分,理论上,该类允许应用在特定用户配置文件下运行。我能够列出这些配置文件:

List<UserHandle> userProfiles = userManager.getUserProfiles();

但是我没有找到一种方法(谷歌的文档也没有展示)如何使用和访问CrossProfileApps的方法。该类的构造函数不是公开的,因此我无法简单地进行如下操作:

CrossProfileApps foo = new CrossProfileApps();

这些方法也不是静态的,无法这样使用:

var foo = CrossProfileApps().fooMethod();

总之,我想要解决的问题是:如何使用CrossProfileApps类并使用它的方法来在指定的用户配置文件下运行我的应用程序或单个活动?

英文:

I'm developing a application which needs to be run from my smartphone's work profile. I've read Google's documentation on work profile and, specificaly,the CrossProfileApps class, which, in theory, allows the app to run under a specific user profile. I am able to list the profiles:

List&lt;UserHandle&gt; userProfiles = userManager.getUserProfiles();

But I didn't figured out a way (and neither does the Google documentation shows) how to use and access the CrossProfileApps methods. The class constructor isn't public, so I cannot just

CrossProfileApps foo = new CrossProfileApps();

And neither are these methods static to do such:

var foo = CrossProfileApps().fooMethod();

Getting to the bottom of my question: how do I make use of the CrossProfileApps class and use it's methods in order to run my app or a single activity under a specified user profile?

答案1

得分: 0

我相信这是

CrossProfileApps crossProfileApps =(CrossProfileApps)context.getSystemService(Context.CROSS_PROFILE_APPS_SERVICE);

同时确保您的API版本在28或更高。

英文:

I believe it's

CrossProfileApps crossProfileApps = (CrossProfileApps) context.getSystemService(Context.CROSS_PROFILE_APPS_SERVICE);

Also make sure you're on API 28 or higher

huangapple
  • 本文由 发表于 2020年7月23日 21:13:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/63055141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定