我有两个应用都启用了信息亭模式。我目前从一个发送广播到另一个传输数据。我想告诉接收应用程序开始一个新的 Activity 。
在大多数情况下,我可以使用 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);然而......我无法在信息亭模式下开始新任务。
这是我在 broadcastReceiver 中的内容(我已经验证了它对其他数据有效)。此代码尝试启动新 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());
}
我在添加标志之前的错误:
Kiosk Mode: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
添加标志后:
E/ActivityManager( 470): Attempted Lock Task Mode violation
是否可以通过广播接收器发送上下文,以便我可以使用该上下文启动所需的 Activity ?除了使用广播开始新 Activity 之外,谁能建议另一种方法?
最佳答案
注意:在 Android“ScreenPinning”中,“Kioskmode”和“Lock Task Mode”是相同的。
来自 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.
您必须使用 stopLockTask() 交互临时禁用 kioskmode 并使用 startLockTask() 重新启用它
为了防止 android 要求用户重新启动 kioskmode,您还需要实现 https://developer.android.com/about/versions/android-5.0.html#DeviceOwner应用
您可以在 https://github.com/Tuong-Nguyen/Android/wiki/Research-114-Kiosk-Mode-Android-application 找到有关此主题的大量信息。
关于android - 如何在信息亭模式下从另一个应用程序开始新 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48190538/