Reputation: 300
I have two apps that both have kiosk mode enabled. I currently send a broadcast from one to the other that transmits data. I want to tell the receiving app to start a new activity.
In most cases I would be able to use intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); however... I am not able to start a new task while in kiosk mode.
Here is what I have in the broadcastReceiver(which I have verified works for other data). This code tries to start a new activity:
Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this doesn't work in kiosk mode...
launchIntent.setComponent(new ComponentName("my.package","my.package.myactivity"));
try {
if(launchIntent != null) {
context.getApplicationContext().startActivity(launchIntent);
Log.i(TAG, "Started activity");
} else
Log.i(TAG, "Intent is null");
} catch (Exception e) {
Log.e(TAG, e.toString());
}
My error before adding the flag:
Kiosk Mode: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
And after adding the flag:
E/ActivityManager( 470): Attempted Lock Task Mode violation
Is it possible to send a context through a broadcast receiver, perhaps, so that I can start the desired activity using that context? Can anyone suggest another method other than using broadcasts to start new activity?
Upvotes: 1
Views: 2225
Reputation: 14755
Note: In Android "ScreenPinning", "Kioskmode" and "Lock Task Mode" are the same.
from https://developer.android.com/about/versions/android-5.0.html#ScreenPinning
Once your app activates screen pinning, users cannot (...)
access other apps (...) until your app exits the mode.
You have to temprary disable the kioskmode with stopLockTask() interact and re-enable it with startLockTask()
To prevent android from asking the user to re-start kioskmode you also need to implement a https://developer.android.com/about/versions/android-5.0.html#DeviceOwner app
You can find a lot of infos about this topic at https://github.com/Tuong-Nguyen/Android/wiki/Research-114-Kiosk-Mode-Android-application
Upvotes: 3