Good day.
How to make an activity that can not be closed. The device is used as a measuring device, the user does not have to access other functions.
I check in the service whether the activity is running and if I don’t start it, but on some phones after pressing the home button you can manage to get into the dialer, some in the settings and at the same time the activity does not sound

while (!Setting.getPassword(getApplicationContext()).equals(CryptoUtil.getHash(Setting.SALT1 + Setting.pseudoID+Setting.SALT2) )){ AudioManager aManager = (AudioManager) getSystemService(AUDIO_SERVICE); aManager.setRingerMode(aManager.RINGER_MODE_SILENT); if (!isRunning(getApplication())) { Intent dialogIntent = new Intent(getBaseContext(), MyActivity.class); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } } public boolean isRunning(Context ctx) { ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(Integer.MAX_VALUE); for (ActivityManager.RunningTaskInfo task : tasks) { if (ctx.getPackageName().equalsIgnoreCase(task.baseActivity.getPackageName())) return true; } return false; } 
  • 2
    make the application as a launcher, it will open when loading and cannot be turned off with the HOME button - Kaminsky
  • however, if the user gets to the settings, he will be able to change the launcher. - KoVadim
  • one
    I really hope that your malware won't work without root ... - Vladyslav Matviienko
  • @metalurgus will then rank the e-menu in restaurants, storekeepers applications in conjunction with 1c and many others, where a device is given to an employee / client and go somewhere else - gadfil
  • @gadfil, this is malware purely by definition of malware ... - Vladyslav Matviienko

1 answer 1

In android 5.0, a special API has appeared for implementing kiosk mode applications - "Screen pinning" .

You can activate it for your application in two ways:

A more detailed description can be found in the article Implementing Kiosk Mode in Android - Part 3: Android Lollipop

If you need for android earlier versions, you can see the article "How to Create a Working Kiosk Mode in Android" . In it, the author has collected a huge number of hacks and workarounds for applications on android 4.0

To solve the problem with the home button, you can use the car mode and temporarily override home:

  <activity android:name="sdg.example.car_mode.CarModeDemo" android:label="@string/app_name" android:launchMode="singleInstance" > <!-- Don't run multiple copies --> <!-- Have the Home key give us control instead of the Home app --> <meta-data android:name="android.dock_home" android:value="true" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.DEFAULT" /> <!-- Become the Car Mode activity --> <category android:name="android.intent.category.CAR_DOCK" /> </intent-filter> </activity> 

Source: Implementing Kiosk Mode in Android - Part 1