Require a password to run certain applications?

I would like to try and implement the function presented in this application

That is, the user must enter a password to run certain applications. I'm not sure which direction to go next.

+3


source to share


3 answers


Not possible out of stock. Best of all, you can write a custom launcher that requires a password to run certain applications. The user can always change the launcher to a spare, so not very useful as a safety feature. May work if you want your (young) children not to have access to your Gmail, etc. There are certain hacks that make it look doable, but nothing is foolproof.



0


source


I think there must be a service in the background. If it detects starting any new action check if the password is protected, if yes then it will display the security screen.



+1


source


This solution might help you.

Extract it:

Store a long variable with the system time when the activity was suspended.

   import android.app.Application;
    public class MyApplication extends Application {
        public long mLastPause;

        @Override
        public void onCreate() {
            super.onCreate();
            mLastPause = 0;
            Log.w("Application","Launch");
        }
    }

      

In each onPause method, I update this value to the current time.

@Override
public void onPause() {
    super.onPause();
    ((MyApplication)this.getApplication()).mLastPause = System.currentTimeMillis();
}

      

And in each onResume compare it with the current time. If a certain amount of time is displayed (currently 5 seconds), my password prompt is displayed.

@Override
public void onResume() {
    super.onResume();
    MyApplication app = ((MyApplication)act.getApplication());
    if (System.currentTimeMillis() - app.mLastPause > 5000) {
        // If more than 5 seconds since last pause, prompt for password
    }
}

      

0


source







All Articles