How to create android app lock application example


          In this article i am going to show you how to create the app like AppLock, how to protect your application from the unknown users.

          Most of the user i think aware about the AppLock that will lock your app but using this article you will know how actually that works.

         

          Using following these steps you can achieve your target to lock any application in android.

          1.  Detect Which app is in the foreground and check in every app change event
          2.  If any new app is in foreground that open the password screen and if password is right then close that screen.


           You can use the following code to implement that functionality - 

Where MyService is a service that will run in background and will lock the app when any new app will open we need to start the service to achive this... 
------------------------------------------------------------------------------------

public class MyService extends Service
{
    private static Timer timer = new Timer(); 
    public Boolean userAuth = false;
    private Context ctx;
    public String pActivity="";

    public IBinder onBind(Intent arg0) 
    {
          return null;
    }

    public void onCreate() 
    {
          super.onCreate();
          ctx = this; 
          startService();
    }

    private void startService()
    {           
        timer.scheduleAtFixedRate(new mainTask(), 0, 500);
    }

    private class mainTask extends TimerTask
    { 
        public void run() 
        {
            toastHandler.sendEmptyMessage(0);
        }
    }    

    public void onDestroy()
    {
          super.onDestroy();
          Toast.makeText(this, "Service Stopped ...", Toast.LENGTH_SHORT).show();
    }

    private final Handler toastHandler = new Handler()
    {
        @Override
        public void handleMessage(Message msg)
        {
        String activityOnTop;
        ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> RunningTask = mActivityManager.getRunningTasks(1);
        ActivityManager.RunningTaskInfo ar = RunningTask.get(0);
        activityOnTop=ar.topActivity.getClassName();
       
        if(activityOnTop.equals("com.dheeruapps.MainActivity"))
        {
        pActivity = activityOnTop.toString();
        }
        else
        {
        if(activityOnTop.equals(pActivity) || activityOnTop.equals("com.dheeruapps.LockScreen"))
        {
       
        }
        else
        {
        Intent i = new Intent(MyService.this, LockScreen.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(i);
            Toast.makeText(MyService.this, pActivity, 1).show();
            pActivity = activityOnTop.toString();
            
        }
        }
       
       
        /*if(!activityOnTop.equals(pActivity))
        {
        if(!activityOnTop.equals("com.javacodegeeks.android.androidserviceexample.LockScreen"))
        {
        pActivity =activityOnTop;
        }
        else
        {                                                                                                                                                                                                                                                                                                                                                                   
        Intent i = new Intent(MyService.this, LockScreen.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(i);
            Toast.makeText(MyService.this, pActivity, 1).show();
            
        }
        }
        else
        {
        Toast.makeText(MyService.this, "Hi", 1).show();
        }
        */
       
       
        }
    };    
}




19 comments

  1. What if a user close your application from background, your service will give a delay and that user can use locked app easily. what is the solution of this problem?

    ReplyDelete
  2. https://play.google.com/store/apps/details?id=com.amazing.secreateapplock&hl=en

    ReplyDelete
  3. Valuable information in your blog and I really appreciate your work and keep it up dude I really very informative blog about the App locker nice work.
    App locker

    ReplyDelete
  4. I love this app. My only complaint is that every time I unlock, within 10 seconds my set goes to sleep. I cannot wake from track pad, I have to bang on my space bar for the computer to wake back up. Suggestions?
    Gallery lock

    ReplyDelete
  5. This is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article. I really like the fresh perceptive you did on the issue. I will be back soon to check up on new posts! Thank you!
    android apps market

    ReplyDelete
  6. Hello! This post couldn't be written any better! Reading through this post reminds me of my good old room mate! He always kept chatting about this. I will forward this page to him. Fairly certain he will have a good read. Many thanks for sharing!
    tv apps

    ReplyDelete
  7. getRunningTasks() function is deprecated in android version 21.
    This will work in lollipop and above

    ReplyDelete
  8. Do you have any other solution for lollipop and above vesion?

    ReplyDelete
  9. Anyone can work for me for android project
    For developing module like website blocking etc

    ReplyDelete
  10. Nice Blog.....thanks for this.... Just visit App in Minute can create Application and website without burden. App In Minute has the affordable Pricing and Making Plan by App In Minute of Rs. 5 / Day (Rs.1825/ Year.) It can be develop your free android application , website product and service to the world. for more information about how to create an app

    ReplyDelete
  11. Nice blog. Thanks for sharing such great information. App In Minute DIY Tool (Do It Yourself Tool) is the Web Application which lets you create your Android Mobile Application & Website which are integrated with E-Commerce. Develop Your Android App & Website to boost your business tremendously. With this tool, Appinminute provides APIM Store that lets you display your app to the world so that anyone can reach you from any corner of the world and download your application. For more information https://www.appinminute.com/

    ReplyDelete
  12. applock is a lightweight application that gives you a chance to bolt practically any sort of document on your Android.

    ReplyDelete
  13. best app lock for android
    very nice app ...
    great information..
    same article here

    ReplyDelete
  14. For a long time, I didn't want to do it, instead I used Applock for my phone, great, all my data is safe, I feel very reassured about it.
    Applock is the best application I've used

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. To create app locker in android studio you need consider 5 things

    1. Usage Stats Services

    2. Background Services

    3. Broadcast Receiver

    4. Sqlite Database

    5. Lock Screen

    I found detail code and explanation here : https://www.codervlogs.com/2019/03/how-to-make-app-locker-in-android.html

    ReplyDelete

My Instagram