简体   繁体   中英

Quitbutton for Kiosk-Mode App

I am looking for a solution for quiting an kioskmode-application on an Android.

Out application is running in Kioskmode to prevent accidential closing by hitting back or home buttons, but we need to close it on request. Does anybody have any solution for that?

We implementet kioskmode by adding

AndroidManifest.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"/>

I use this code:

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);
}

Maybe it works for you as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM