1



I'm developing an Android app for a company where those who will use it are the employees, for this reason the company asked me to develop an application that the user can not close, because if he will not use the smartphone for other purposes, but for this I need the Android native buttons do not interfere with the application.

I've deactivated the button to go back and put the application as Home.

@Override
     public void onBackPressed () {
         super.onBackPressed ();
     }

...

<category android: name = "android.intent.category.HOME" />

However if the user clicks the button that displays open applications, it can exit the application.

I researched a lot before creating resolve this question and realized several attempts to solve this problem.

One. I tried to create the same behavior as the MX Player has, when you use the lock to see a video, the MX Player is always on top of everything, leaving the user to see and click others places. However using this behavior does not i cant see My Dialogs nor Popup and also can not apply a thema, as in my case is not simply an activity is the entire application.

Reference links of my attempt
How to disable Home and other system buttons in Android?
http://www.piwai.info/chatheads-basics/

If anyone knows how to use that behavior MX Player, or if anyone knows any more how to make the user can not close the application, please help me, I know it's not just me who have this problem.

Any help is welcome!

My API is 16 - Android-4.1

Community
  • 1
  • 1
Busata
  • 899
  • 1
  • 10
  • 25
  • 2
    possible duplicate of [Kiosk mode in Android](http://stackoverflow.com/questions/2068084/kiosk-mode-in-android) – Matt Ball Jan 27 '15 at 18:47
  • Please could you specify what is the answer ? Thank you – Busata Jan 27 '15 at 19:02
  • lollipop has a new kiosk mode that would work – njzk2 Jan 27 '15 at 20:20
  • `the button that displays open applications` that's the `Recent Apps` button – njzk2 Jan 27 '15 at 20:20
  • there is that : http://stackoverflow.com/questions/14574239/how-to-disable-the-recent-tasks-apps-button-in-android – njzk2 Jan 27 '15 at 20:21
  • First thanks for your @njzk2 help, I tried this and it only works if you have no open or Dialog Popup because apply their standards, thus ignoring the "onWindowFocusChanged" my Activity. I created a Dialog with "onWindowFocusChanged" but has no way to create a Popup with this method. :/ – Busata Jan 28 '15 at 10:26

3 Answers3

0

Are your target devices rooted? If so, this article goes through the steps to make this possible. What you specifically ask about can be done by modifying the build.prop file to include the following line: qemu.hw.mainkeys=1. This will stop the soft-key navigation bar from ever showing up.

If the device you're running isn't rooted, I don't think that it's possible to do what you're asking.

vdelricco
  • 719
  • 4
  • 15
0

The best way i found to the user can't access others apps, was to make a service that check which is the top activity, if don't is my then reopen my app.

ActivityManager manager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> runningTasks = manager.getRunningTasks(1);

if (runningTasks != null && runningTasks.size() > 0) {
    ComponentName topActivity = runningTasks.get(0).topActivity;

    if (!topActivity.getPackageName().startsWith("com.mypackage.")) {
        Log.i("Top Activity", topActivity.getPackageName());
        if (LocalCache.getInstance().isForceHome()) {
            Intent intent = new Intent(HomeService.this, AuthLoginActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    }
    handler.postDelayed(this, 500);
}
Busata
  • 899
  • 1
  • 10
  • 25
0

Old question, but I'm facing exactly same situation:

  • In-house App
  • Can't be close

I'm going to set App as a Launcher, and block top-dowm swipe to prevent status bar appear.

I think it's good enough for an in-house App ~

RRTW
  • 3,044
  • 1
  • 34
  • 52