Display a Toast message when Android for Work configuration is missing

138 views Asked by At

I'd like to prevent my application from starting when an Android for Work profile is not available for my application (not yet configured, or deployed on the device). Instead, I'd like to be able to display a Toast like message telling the user to contact his IT administrator. Example of this at the bottom of this message.

Example: Divide Productivity Suite of application displays this message (mail, notes, etc).

"Configuration from managing application required. Contact your IT admin for details".

Screen Capture

Is there a way to implement this? I've tried to hook into MainActivity onCreate function, or even put it directly in the Application onCreate() function. Hooking code in here seem to still have launched the application (the title bar is displayed despite there's no content displayed).

I was able to figure out how to determine if your Application was running on a for Work profile and display a alert dialog here: Android for work - How to check if my application is running in the work profile?

2

There are 2 answers

0
Yasin Kaçmaz On

Man i can give you specific topic . You can search for services instead of Activities. Activity codes performing only when application is running . But you can call services everytime without your app is not running.

You can look here

0
Eivind On

Apparently, this was actually pretty trivial.

  • In your AndroidManifest.xml, you reference a new Activity that starts your main application. This activity will use the "Theme.Translucent.NoTitleBar"
  • When you are unable to configure Android for Work profile, use a Toast.makeToast() message to notify your user, then call finish() and return from your onCreate() function.
  • When you are able to complete Android for Work configuration, start your MainActivity by creating an Intent, set the action and category and then call startActivity() from your initial Activity.