Work profiles are Android's built-in experience
for when personal devices are being used to access work.
They separate work apps and data from personal apps and data.
Apps installed in a work profile are marked with a small briefcase icon
to distinguish them from personal apps.
Organizations can securely manage work profiles,
all while keeping personal apps separate and hidden.
When a device is enrolled by an organization,
the work profile is set up with some pre-installed apps.
These include a managed Play Store app
that lets employees install and run apps in their work profile.
For an app to run reliably in a work profile,
you don't really need to do much besides ordinary app development best practices.
However, some of these best practices
become especially important on devices with work profiles.
Apps that get installed in the personal profile
can still use some of these work profile features
to provide a better cross-profile user experience.
For example, if an app allows the user to search for contacts,
why not let them search in both personal and work contacts?
That's what the Android Contacts app does.
You can see that it presents both personal and work contacts
in the same view.
To include work contacts in your app,
you can use the Enterprise Content Filter URI.
It's meant to be a drop-in replacement for the standard content filter URI.
The documentation includes details on how to use it
as well as some useful URI guidelines
on how to nicely present both work and personal contacts
in the same view.
Files are also stored separately in a work profile.
If a work app needs to access a personal file,
like sharing a personal photo using a work chatting app,
you'll need to make sure that the app has the right permissions to access that file.
Content URIs are a safe option to share files across profiles.
Because they include the permissions along with the file path.
It's recommended to use content URIs over file URIs in general.
And if users browse and pick a file on their device,
you can consider using the Storage Access Framework.
It comes with UI components that helps users navigate and pick a file.
And it detects if a work profile is setup,
and then combines both personal and work files
at the same time, allowing users to pick and choose files
without having to leave the app.
Apps that are frequently used in both profiles, like email apps,
can present the user with an easy way
to switch from one profile to the other from within the app.
Take Gmail, for example.
It detects if it's installed in both profiles
and then offers the user an easy way to switch from one profile to the other.
To implement a similar flow in your app, use the CrossProfileApps class.
It has APIs that can detect if other profiles are set up
and help you switch between them.
Remember that work profiles are managed by IT admins,
which means essential device features and apps
might be restricted at runtime, things like disabling the camera,
Bluetooth, or even overriding app permissions.
So you need to be extra careful when dealing with runtime events,
especially launching intents.
To be safe,
always check if there is a valid app ready to handle an intent
before launching it.
To find out if there's a valid intent handler,
you can use the package manager's resolve activity.
If it returns null, it means that no app can handle that intent.
If it returns anything else, then you can safely launch it.
Your app can also provide great value to work users and IT admins
by using managed configurations.
They allow you to expose any setting in your app
to be remotely configured by IT admins.
This helps organizations adopt your app for work
since they'll have more control over how it behaves.
Test your app for work profile compatibility using TestDPC.
It's an app that's built by Google, and it's made available on the Play Store.
It helps you set up a work profile on any device,
including emulators, and it has a list of extensive controls
that can help simulate IT admin changes and restrictions.
And since it's open source, you can check out the code
and understand how some of these management features work.
In summary, best practices are important.
Some practices are crucial when developing any app,
like checking for a valid intent handler before launching an intent
or using content URIs instead of file URIs.
Other best practices are very valuable if your app is targeting enterprises.
If your app is interacting with contacts,
consider including work contacts in your app flow.
If your app is installed in both a personal and a work profile,
consider including an option for users to switch from one profile to the other
within the app itself.
Consider using managed configurations
if you want to expose settings to IT admins.
And finally, install and test your app using TestDPC.
Make sure your app is 100% work profile compatible.
To know more about work profile features and best practices,
check out developers.android/work,
or complete the work profile codelab,
which covers how to implement what we talked about
as well as how to use TestDPC.