Query Intent Activities for Different Profiles : Android for Work
Asked Answered
R

1

6

For some technical reasons, I cannot use Android File Picker to get a file and their content into my application. That's why I came up with a solution which queries intents and processes the results on my own UI.

Here is how I get the list of applications with Intent.ACTION_GET_CONTENT

/* Create a new Intent to Read a File */
Intent documentIntent = new Intent(Intent.ACTION_GET_CONTENT);
documentIntent.setType((action == ACTION_SELECT_FILE) ? "*/*" : "image/*");

/* Query for Applications to see which are available */
List<ResolveInfo> appList = getActivity().getPackageManager().queryIntentActivities(documentIntent, PackageManager.MATCH_DEFAULT_ONLY);

This works fine and lists the applications which can handle my request.

But I'm working with Android for Work and when I execute the code above, I only get the list of applications available to Work Profile, which is expected.

But one of the results which is returned from the code above is "Switch to Personal" which lists applications installed in Personal Account in Android File Picker.

So the question is, how can I get the same behavior? How can I Query Intent Activities from Personal Profile?

Ruffi answered 9/2, 2018 at 22:15 Comment(2)
Please correct me if I am wrong but I guess what you are trying is to use an app [any app for that sake] installed on Personal profile and then launch it from your app running in the Work profile? is it so?Mandatory
@Mandatory kind of. I'm trying to get the list of apps that can handle GET_CONTENT action in the personal profile. So I can launch (e.g File Explorer App) it and get data from this app into my Application working under Work Profile.Ruffi
M
0

I don't have much idea about Android for Work, but it's mentioned in the Developer Guide that

The Android system prevents intents from crossing profiles and IT administrators can enable or disable system apps.

So my guess would be that you cannot access/start an Activity in Personal profile from an application installed in the Work profile and vice-versa.

But as mentioned in this StackOverflow post, if your app is a Device Policy Controller, then you can implement the DevicePolicyManager#clearCrossProfileIntentFilters(ComponentName admin) and allow the intent to cross profiles.

Another consideration would be sharing files across profiles, and the documentation states that the developer should use Content URIs instead of File URIs when sharing path between profiles. You can read more about that here.

Mandatory answered 20/2, 2018 at 4:8 Comment(6)
thanks for your comments but the question is not really about Device Policy Controller app or FileProvider (Content URI vs File Paths). And it's possible to send data between Work and Personal Profile. Normally, Google uses IntentForwarder for forwarding Intents from Work to Personal Profile. But unfortunately, these methods have 'hide' annotation so we cannot access them and I don't really want to create a workaround to expose these methods.Ruffi
I guess this is what is meant when the documentation says that " system prevents intents from crossing profiles". I am sure there is bridge as you stated, but to access that you need to implement DevicePolicyManager. P.S. just speculations, maybe you could provide more detail here.Mandatory
Google uses IntentForwarder for forwarding Intents from Work to Personal Profile. Can you cite some source, like, code or something?Mandatory
DevicePolicyManager is for device owners or managers, which is for MDM Providers, not for apps work under Work Profile. With device policy manager, you can filter apps that your "user" in your organization can have access or not. This is not our subject. In my question, I'm interested in querying available intents from the personal profile. So if the Device Owner or Manager blocks apps, the user won't be able to get them in Query Result.Ruffi
And for IntentForwarder, I've found it in the source code. If you debug the QueryIntentActivities, as stated in my question, one of the results you will get is "Switch to Personal". If you debug this result, you will see the Intent's detail where IntentForwarder can be found as the destination of this Intent.Ruffi
So it's possible for System Apps to use this method and my question was about learning if it's possible to have a similar way for us.Ruffi

© 2022 - 2024 — McMap. All rights reserved.