QNA > H > How To Create An App Locker In Android Studio

How to create an app locker in Android Studio

Get list of all installed app by following code.

  1. final PackageManager pm = getPackageManager(); 
  2. //get a list of installed apps. 
  3. List packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); 
  4.  
  5. for (ApplicationInfo packageInfo : packages) { 
  6. Log.d(TAG, "Installed package :" + packageInfo.packageName); 
  7. Log.d(TAG, "Source dir : " + packageInfo.sourceDir); 
  8. Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));  

Check for which app is opened currently

  1. ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); 
  2. List l = am.getRecentTasks(1, ActivityManager.RECENT_WITH_EXCLUDED); 
  3. Iterator i = l.iterator(); 
  4. PackageManager pm = this.getPackageManager(); 
  5. while (i.hasNext()) { 
  6. ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next()); 
  7. try { 
  8. CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo( 
  9. info.processName, PackageManager.GET_META_DATA)); 
  10. Log.w("LABEL", c.toString()); 
  11. } catch (Exception e) { 
  12. // Name Not FOund Exception 

Now check if the current app is present in the BlockedAppsList, if it is there, you can show any screen with a block message.

You need to create service which will run in background.

Di Hartman Giumarro

L'HTC One M9 vale l'acquisto rispetto a un iPhone? :: Come fanno i raggi dello schermo di un telefono cellulare a danneggiare gli occhi?
Link utili