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.
source to share
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.
source to share
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
}
}
source to share