Question

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"/>
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top