1

I'm trying to create a lock screen that prevents access to an application when it starts but I can't find answers. I'm not sure how to implement the code. Also in most cases it's mentioned that it was deprecated in android 5.1 and higher.

(I´m working in android 7.1)

These are the links:

Android, Detect when other apps are launched

How to check current running applications in Android?

how to know when other app is launched in android

Hiroga Katageri
  • 1,345
  • 3
  • 21
  • 40
Marx
  • 13
  • 3

1 Answers1

0

You have to create your background service for that , which will continuously monitor top app in device .

So first of all make a service which will start after your app launch .In your service , use this

ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> RunningTask = mActivityManager.getRunningTasks(1);
ActivityManager.RunningTaskInfo ar = RunningTask.get(0);
activityOnTop=ar.topActivity.getClassName();

activityOnTop will give you the current running app in your phone . Now show lock screen after getting top activity.

Tejas Pandya
  • 3,987
  • 1
  • 26
  • 51