How to make app locker in android studio source code

How to make App locker in Android studio in Oreo

App Locker in Android Studio


In this article , you will learn how to create basic app locker for android studio and which support on all apis  including latest apis because when I was creating app locker I found all tutorials and website are using methods which are supported by latest apis, in short they are useless. So in this article we will cover app locker which will support on all apis and goal is to provide quality solution thats really helps you. Now let’s discuss our app that is app locker. What functionalities we will cover in this app, let me tell you this app is simple, later on we will add some advanced functions like open with puzzle, fingerprint and face lock but for now we will use simple password to lock and unlock app. These are some of functionality of our basic app locker 
  1. App locker should show list of installed apps with status of locked and unlocked.
  2. App locker should lock and unlock app with password.
  3. App Locker allow to update and set new password.
  4. App Lock open lock screen when user open locked application.
  5. App locker will continuously track or detect which app is running in background.

How can we create App Locker in Android Studio

 

You can create app locker with different logic, I will help you to understand what is required for implementing, I will explain my way so you can use it as example. To create app locker in android studio you need knowledge in these things are

  1. Usage Stats Services (detect current running app)
  2. Background Services (need separate process or thread for checking which app is currently running)
  3. Broadcast Receiver (restart background services on phone reboot)
  4. Sqlite Database or shared preference (keep records of locked applications)
  5. Lock Screen 
Usage Stats Services is used for telling which app is running on android device at current time, so app locker will detect  app using this services. The purpose of background services is to launch lock screen when detected app is found in database with status of locked , similarly broadcast receiver is used to restart background service when your background services are destroyed during phone restart or shut down. Sqlite database is used for saving your password and list of  apps stored with package name and its status ( lock or unlock ). Lock screen will stop any launched app if it is found in app locker database with locked status and it will open when user enter password correct.
 
How to make App locker in Android studio Oreo

App Locker Helping Code in Android Studio


I will share some part of code that will help a lot in implementing app locker. First code is for Broadcast receiver, this code will be called when your phone is rebooted, so broadcast receiver will reactivate  your background services.
				
					import android.content.BroadcastReceiver;

import android.content.Context; 

import android.content.Intent; 

import android.os.Build; 

import android.util.Log; 

public class RestartService extends BroadcastReceiver { 

@Override public void onReceive(Context context, Intent intent) { 

if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { 

Log.i("Broadcast Listened", "Service tried to stop"); 

//Toast.makeText(context, "Service restarted", Toast.LENGTH_SHORT).show(); 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 

context.startForegroundService(new Intent(context, BackgroundServices.class)); 

} 

else {

 context.startService(new Intent(context, BackgroundServices.class)); 

} 

// context.startService(new Intent(context.getApplicationContext(), NotificationService.class)); 

} 

Log.i("Broadcast Listened", "Service tried to stop"); 

//Toast.makeText(context, "Service restarted", Toast.LENGTH_SHORT).show(); 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 

context.startForegroundService(new Intent(context, BackgroundServices.class)); 

} 

else { 

context.startService(new Intent(context, BackgroundServices.class)); 

}

 }

 }
				
			

Very important code and that is how to track which app is currently running using stats services, code will return package name of app, below is the code 

				
					private void printForegroundTask() {
    String currentApp = "NULL";
    if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        UsageStatsManager usm = (UsageStatsManager) this.getSystemService(Context.USAGE_STATS_SERVICE);
        long time = System.currentTimeMillis();
        List<UsageStats> appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,  time - 1000*1000, time);
        if (appList != null && appList.size() > 0) {
            SortedMap<Long, UsageStats> mySortedMap = new TreeMap<Long, UsageStats>();
            for (UsageStats usageStats : appList) {
                mySortedMap.put(usageStats.getLastTimeUsed(), usageStats);
            }
            if (mySortedMap != null && !mySortedMap.isEmpty()) {
                currentApp = mySortedMap.get(mySortedMap.lastKey()).getPackageName();
            }
        }
    } else {
        ActivityManager am = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> tasks = am.getRunningAppProcesses();
        currentApp = tasks.get(0).processName;
    }

    Log.e(TAG, "Current App in foreground is: " + currentApp);
}

				
			

Get App Locker Code for Android Studio

 
Unfortunately, App locker project source code is not free, you will pay 20$ for it, but you can get it free if you support my Youtube channel ( Coder Vlogs ), to increase my subscriber to 1000 and one more bad news the code I have is supported in Oreo API Only after that API it will not work but i know the solution to make app locker working in latest API, I will give you hint.
 

In the latest API, google add restriction on background services and I was using background services in it, So for latest api you will use job scheduler instead of background service. That is simple solution.

Now let’s talk about buying code, so you will get code easily but that will be supported on Oreo API for now, New Source code which supported on latest api will be available after 1000 subscriber on youtube channel. You want to check demo below is link and paypal id for support or purchase code.

App Demo link : https://play.google.com/store/apps/details?id=com.saifyproduction.simpleapplocker

Paypal ID :  https://www.paypal.com/paypalme/CoderVlog

 

For more you can contact me on Facebook and watch App locker series on youtube here :  https://www.youtube.com/watch?v=PhbjbzNE43U&list=PLig0Ac3oXn9xvJGTJLc16K1qkU3FaVMv-

 

 
Table of Contents

Next Articles

Related Articles