Casa > 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.

De Sukhum Barsallo

Porque é que o meu telemóvel só pode aceder à Internet através do router wifi quando um portátil está ligado e a aceder à rede? :: Quero um Nintendo Switch mas os meus pais não estão a concordar em comprar-me um Como posso convencê-los a comprar-me um?