Skip to main content

Android Lock Apps


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!


Source: Tips4allCCNA FINAL EXAM

Comments

  1. 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;
    }

    ReplyDelete
  2. That service that checks every second will drain your battery in a couple hours.

    Wouldn't it be better to make a launcher / home app?

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.