Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Lock Apps

Tags:

android

I'm new here and I've searched for questions to help me but I have no clear answers.

I need to make an application to block other applications on the phone. I've seen several on the market but I want to make one. is there any way of knowing when a user tries to open an application and bring forward an activity? (to put the password).

I tried with FileObserver, but only works with files and directories (obviously). Could I make a listener that captures the Intent of the other applications before starting?

I apologize for my english and I appreciate your help!

like image 888
ngbl Avatar asked Aug 30 '11 18:08

ngbl


People also ask

How can I lock apps on Android?

Go to your app drawer and tap “Secure Folder.” Tap “Add apps.” Select all the apps you want in the folder, then tap “Add” in the upper right corner. Tap “Lock” back in the Secure Folder menu. Try to access an app you added to the folder and make sure it prompts you for your passcode or fingerprint.

How do I lock certain apps?

Select Pattern, Pin, or Password (or a biometric option, if available), then continue by entering your selection and confirming it. Select Secure Folder from the app drawer, then tap Add apps. Select the apps you wish to include in Secure Folder, then tap Add. Select Lock and exit in the upper-right corner.

Does Android have an AppLock?

AppLock is another one of the better applocks on Android. Like you'll see, it can lock pretty much any app on your phone. It also boasts the ability to lock photos and videos.


1 Answers

No you cannot know when another application is launched without some kind of hack. This is because application launches are not broadcasted.

What you can do is creating a service running on fixed intervals , say 1000 milliseconds, that checks what non system application is on front. Kill that app and from the service pop a password input box. If that password is correct relaunch that application

Here is some code sample

    timer = new Timer();     timer.scheduleAtFixedRate(new TimerTask() {         public void run() {               List<RunningAppProcessInfo> appProcesses= activityManager.getRunningAppProcesses();         for (RunningAppProcessInfo appProcess : appProcesses) {             try {             if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {             if (!lastFrontAppPkg.equals((String) appProcess.pkgList[0])) {             apkInfo = ApkInfo.getInfoFromPackageName(appProcess.pkgList[0], mContext);                 if (apkInfo == null || (apkInfo.getP().applicationInfo.flags && ApplicationInfo.FLAG_SYSTEM) == 1) {                   // System app                                             continue;                         } else if (((apkInfo.getP().versionName == null)) || (apkInfo.getP().requestedPermissions == null)) {                     //Application that comes preloaded with the device                         continue;                      } else {                      lastFrontAppPkg = (String) appProcess.pkgList[0];                      }     //kill the app     //Here do the pupop with password to launch the lastFrontAppPkg if the pass is correct                          }                       }                    }                  } catch (Exception e) {                   //e.printStackTrace();                 }                }                                      }            }, 0, 1000); 

And here is the ApkInfo.getInfoFromPackageName()

    /**  * Get the ApkInfo class of the packageName requested  *   * @param pkgName  *            packageName  * @return ApkInfo class of the apk requested or null if package name  *         doesn't exist  * @see ApkInfo  */ public static ApkInfo getInfoFromPackageName(String pkgName,         Context mContext) {     ApkInfo newInfo = new ApkInfo();     try {         PackageInfo p = mContext.getPackageManager().getPackageInfo(                 pkgName, PackageManager.GET_PERMISSIONS);          newInfo.appname = p.applicationInfo.loadLabel(                 mContext.getPackageManager()).toString();         newInfo.pname = p.packageName;         newInfo.versionName = p.versionName;         newInfo.versionCode = p.versionCode;         newInfo.icon = p.applicationInfo.loadIcon(mContext                 .getPackageManager());         newInfo.setP(p);     } catch (NameNotFoundException e) {         e.printStackTrace();         return null;     }     return newInfo; } 
like image 189
weakwire Avatar answered Oct 03 '22 01:10

weakwire