我正在寻找一种在 Android 上退出 kioskmode 应用程序的解决方案。
Out 应用程序在 Kiosk 模式下运行,以防止通过按返回或主页按钮意外关闭,但我们需要根据请求关闭它。有人对此有任何解决方案吗?
我们通过添加
来实现 kioskmodeAndroidManifest.xml:
<uses-permission android:name="android.permission.REORDER_TASKS"/>
[...]android:theme="@android:style/Theme.NoTitleBar">[...]
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT"/>
最佳答案
我使用这段代码:
public void getDefaultLauncher()
{
final Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
PackageManager pm = getPackageManager();
final List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
pm.clearPackagePreferredActivities(getApplicationContext().getPackageName());
for(ResolveInfo ri : list)
{
if(!ri.activityInfo.packageName.equals(getApplicationContext().getPackageName()))
{
startSpecificActivity(ri);
return;
}
}
}
private void startSpecificActivity(ResolveInfo launchable)
{
ActivityInfo activity=launchable.activityInfo;
ComponentName name=new ComponentName(activity.applicationInfo.packageName, activity.name);
Intent i=new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
i.setComponent(name);
startActivity(i);
}
也许它也适合你。
关于android - Kiosk 模式应用程序的退出按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22947909/