I am using device default lock screen in my app for activating and deactivating screen lock. In my application I used a check box which shows that screen lock is activated or not.
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
startActivity(intent);
I am receiving it callback in my DeviceAdminReceiver class.
Methods:onPasswordChanged onPasswordFailed onPasswordSucceeded
Now if user selects none or press back none of these methods get called. I am not able to identify is screen is locked or not ? I used OnActivityResult for handling callback in my Activity, it works fine for back pressed(resultcode 0) but gives same results for all other options.
I found this link which tells that it can't be handled externally.
Summary: I wants to handle screen lock options directly from my application.
if we set password quality on that case user can not able to select none password option
Might it will help you .
We can do this in this way
private ComponentName mDeviceAdmin;
private DevicePolicyManager mDPM;
mDPM.setPasswordQuality(mDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
mContext.startActivity(intent);
Related
Please Please read the question complete before marking it as duplicate or vague
On clicking of a button I want to redirect the user to accessibility settings of the android mobile. Where user can click on the accessibility settings of the application. Here is the code that I am using for the same:
Intent dummyIntent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivityForResult(dummyIntent, 1);
Problem: When user clicks on, I want that it should redirect back to my application and should not remain on the accessibility screen itself.
It's quite late but i had to make the same stuff. So my suggestion is to use onServiceConnected() overridden method in class that extends AccessibilityService . When user apply accessibility in the settings you can launch intent to desired activity inside onServiceConnected(). But you should keep in mind that after device reboot onServiceConnected() also called, so use some flag to make sure that is not user action.
try this :
Intent dummyIntent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
ActivityContext.startActivityForResult(dummyIntent, 1);
My Final project requires that app must be hidden,and never opened again unless entering some code in phone dialer (ex: *123#) can you help me guys to do that task?
This is a bit tricky and it has its up and downs, but what you need to do basically is:
On app install, you need to programmatically disable the app Icon so you cannot open it manually.
Have a BroadcastReceiver registered with the PROCESS_OUTGOING_CALLS intent filter (don't forget to set the uses-permissions).
In the receiver, listen for every dialed number and when it matches yours you need to activate the App Icon again and then you start the activity with possibly extra data to handle it later.
After processing the data in your activity remember to deactivate the icon again.
To programmatically disable the icon use:
PackageManager packageManager = getPackageManager();
ComponentName componentName = new ComponentName(this, MainActivity.class);
packageManager.setComponentEnabledSetting(
componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP
);
To enable it:
PackageManager packageManager = context.getPackageManager();
ComponentName componentName = new ComponentName(context, MainActivity.class);
packageManager.setComponentEnabledSetting(
componentName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP
);
In your receiver to get the dialed number you need to use:
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
// Validate and start your activity here
// To start an activity from a receiver you need to use the flag FLAG_ACTIVITY_NEW_TASK in your intent
}
Note: After hiding the icon programmatically you might want to finish() the activity so it closes automatically at first run.
P.S I have a working sample of this, so rest assured as I have tested it actually works, sadly I cannot spoon feed you in your final project. Don't hesitate to ask anything tho. Good luck
There is no such functionality in Android. You may be able to do it with a custom home screen, but there is no "hide this app" functionality in the default launcher.
I have a share button in the GCM notification. On click of the share button, I need to launch share intent. Everything works perfectly. Only problem that I'm facing is Lollipop lock screen feature. When I click share button from lock screen, my intent dialog appears below the lock screen and user has to unlock the screen to see the dialog. I want to unlock the screen programatically, when share button is clicked.
I tried with Power Manager, But all it's wakeClock flags are deprecated and WindowManager.LayoutParams.Flag_KEEP_SCREEN_ONis recommened to use. But I'm not using activity here. I'm using broadcastReciever context. and hence I cannot use getWindow()method.
I also tried with KeyguardManager. But even disableKeyguard() is deprectated.
I cannot use the Intent.ACTION_SCREEN_ON, as this should be used, if we want to perform any action after screen is unlocked.
i had used below intent to programmatically close the notification tray:
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
mContext.sendBroadcast(it);
Is there a similar intent, that can be broadcasted to unlock the screen
Updated Code using DevicePolicyManager:
public static void handleShareBtnClick(Context context, String message) {
GcmHelper helper = new GcmHelper();
helper.shareMessage(context, message);
if(Utility.isLollypopAndAbove()){
helper.unlockLockScreen();
}
helper.launchShareforForAlert();
}
public void unlockLockScreen(){
DevicePolicyManager devicePolicyMngr= (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName compName=new ComponentName(mContext, DeviceAdminReceiver.class);
if(!devicePolicyMngr.isAdminActive(compName))
devicePolicyMngr.removeActiveAdmin(compName);
}
Even after using DevicePolicyManager, It's not unlocking my screen
Step 1: Add below code in your activity before setContentView(R.layout.example);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
Step 2: Lock your mobile, then you will see activity in which you have added this code.
This will work even though your mobile is locked with pattern lock. This will work like a charm.
I've a problem developing an application, I'm building a Widget that can be either on lockscreen or in home page. when is in lockscreen I want that when the user clicks a button the widget prompt for the user login in case of needed. I mean prompt for patter or password or face recognition depending if the user have any of this security enabled.
after the user enter his pattern the widget will run an application (intent).
I've notice that some widgets does prompt for login and other doesn't I haven't found the difference between them.
I think this has to be on the onReceive method but not sure how can I call this "login" method, so far on the onReceive I start the intent
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.getApplicationContext().startActivity(i);
but this still not prompt for login. when the widget is on the lockscreen.
let say that the user interacts with the widget in the Lock screen, the user is not prompted to enter the password, either way the user does enter his pattern|password and after the user "enter" his home screen and the application is started. So the widget does start the intent just don't let the user "know" or login to see the application.
any thoughts on how can I prompt the user to enter his pattern so it enter to the home screen?
[Edit]
The problem occurs when I try to fire the intent within a BroadcastReceiver.
What I do is allow the user interact with the widgetd buttons, depending on what the user has selected I'll open my application adding some extras to the intent.
so on the onReceive method of my BroadcastReceiver I try to fire:
Intent i = new Intent(context, MyActivity.class);
i.putExtra(WidgetUtils.TAG_CURRENT_SELECTION, StringIGotFromInteraction);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(i);
this way the intent don't prompt for the "unblock".
If in the onUpdate I cast the pending intent to any button when the user clicks that button does prompt for the unlock this way:
views.setOnClickPendingIntent(R.id.aButton, buildAPendingIntent(context));
but I need to know what has the user selected to open and Intent in case I open any.
and my contex.startActivity Approach works fine when the widget is on home screen just not on loockscreen.
Any thoughts how can I make this happen.
I couldn't find the answer what I end up doing was create a dynamic button and when the widget is updated (by the other buttons) I assign the PendingIntent to this button.
So when user clicks this dynamic button the widget attempt to open the intent and is there when the user is prompted for the password.
I think this is not the best solution seance we make the user make an extra click on the widget.
What I am trying to do is replicate what the ToddlerLock app does. I have managed to clear the default launcher with
PackageManager localPackageManager = getPackageManager();
localPackageManager.clearPackagePreferredActivities("com.android.launcher");
and then open the launch select dialog with this
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
As long as the user checks the "use by default for this action" the home key now sends the user to my app, thus essentially disabling it.
I then use "clearPackagePreferredActivities("com.my_application")" when I exit my app and the user has to choose a new default home app.
My question is how can I choose the default home application (essentially checking the "use by default for this action" check box in code for the "com.android.launcher" package. That way the user does not constantly have to see that dialog box every time they open and close my app.
I think ToddlerLock does this somehow without using clearPackagePreferredActivities
because if I look at the "clear defaults" in the application manager it is not cleared and you only have to go through the set as default dialog box one time on startup and once when you exit to set it back to the normal home screen.
Thanks for your help.
I have implemented the same functionality in different way.
Let's say you have 'LockScreenAcitivity' configured as Home Screen in Manifest.
Launch LockScreenActivity by sending Home Intent.
Android will popup a dialog, to select the default Acitivity
choose your LockScreenActivity from List as default Activity
.....
.....
While closing the Activity don't clear the prefered Activities.
Disable your LockScreenActivity alone by calling PackageManager.setComponentEnabledSetting()
After you disable your LockScreenActivity, android will rollback to previous Prefered Activity (that's your old home screen ).
Next time when you launch your app,
enable your lockscreenActivity again by calling PackageManager.setComponentEnabledSetting()
Launch LockScreenActivity by sending Home Intent.