How to remove fingerprint authentication from Android KeyGaurd manager? - android

I've used keyguard manager inside my app to perform some action if and only if the user authenticates using his default device lock credentials, now what is happening is that my device has both fingerprint and pattern/pin lock enabled and when the keyguard manager checks the authentication using isKeyguardSecure method, it starts an activity for result and opens the intent using .createConfirmDeviceCredentialIntent...Now in this intent it asks for the fingerprint by default and gives an option for pin/pattern...I want to disable the fingerprint option in my app, and do not want to remove the fingerprint security from the device itself, just disable it for that particular app or intent.
This is my code:
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
Intent screenLockIntent = keyguardManager.createConfirmDeviceCredentialIntent(title, description);
startActivityForResult(screenLockIntent, LOCK_REQUEST_CODE);
Getting the result in this method
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(LOCK_REQUEST_CODE == requestCode){
if (resultCode == RESULT_OK) {
//Authentication is successful
My App works now
} else {
//Authentication failed
}
}
}
Screenshot showing the fingerprint authentication which I want to remove
This all is working fine, I just want to remove the fingerprint authentication for this particular app and just use the pin/password option...
Thanks in advance ;-)

You can't do that if you are using createConfirmDeviceCredentialIntent(), as this is a system intent and you can't change it. Generally, the screen lock is manged by the OS and will support whatever has been set up (face, fingerprint, iris, PIN, etc.)
You could implement a custom PIN only screen in your app, but that's tricky to do and generally less secure than the one provided by the OS.

Related

Screen Overlay Detected | (Android 6.x) Lenovo, Redmi & Samsung Devices

I have created an app which continuously run in background and show an floating overlay TextView(By using the permission android.permission.SYSTEM_ALERT_WINDOW).
I have problem in Lenovo android devices, when other applications try to request for user permission there is an alert dialog says "Screen Overlay Detected". While I have test the same application on Redmi 3S Prime device the "Allow" button in permission dialog is not clickable, until I have turned off the Floating Overlay TextView in my application.
So is there any solution to resolve this device specific issue? One of the possible solution may be disable floating TextView while permission dialog is visible to user and show floating overlay when permission dialog is closed, but the problem is how can I detect the permission dialog open/close state for other foreground application from my app.
Please suggest...
Unfortunately it seems that this is inherent to the Android OS, and as far as I know there is no way to detect when another app is requesting permissions. The general flow for interacting with other apps is to send intents to them in a push manner, so theoretically it could be done if the other apps send an intent to your app to disable the overlay, though this is not a practical solution.
I could be completely wrong, but I am yet to see a programmatic solution to this problem. The best you can probably do is warn your users that your app may cause this problem, and provide them with a quick temporary disable button.
how can I detect the permission dialog open/close state from my app??
Implement Method Mentioned Below, to run this check at the onCreate of the first Activity
public final static int PERM_REQUEST_CODE_DRAW_OVERLAYS = 1234;
/**
* Permission to draw Overlays/On Other Apps, related to
'android.permission.SYSTEM_ALERT_WINDOW'
in Manifest
Resolves issue of popup in Android M and above "Screen overlay detected- To change this permission setting you first have to turn off the screen overlay from Settings > Apps"
If app has not been granted permission to draw on the screen, create an Intent &
set its destination to
Settings.ACTION_MANAGE_OVERLAY_PERMISSION
&
* add a URI in the form of
"package:"
to send users directly to your app's page.
Note: Alternative Ignore URI to send user to the full list of apps.
public void permissionToDrawOverlays() {
if (android.os.Build.VERSION.SDK_INT >= 23) { //Android M Or Over
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, PERM_REQUEST_CODE_DRAW_OVERLAYS);
}
}
}
Called on the activity, to check on the results returned of the user action within the settings
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PERM_REQUEST_CODE_DRAW_OVERLAYS) {
if (android.os.Build.VERSION.SDK_INT >= 23) { //Android M Or Over
if (!Settings.canDrawOverlays(this)) {
// ADD UI FOR USER TO KNOW THAT UI for SYSTEM_ALERT_WINDOW permission was not granted earlier...
}
}
}
}
NOTE:Above code and extract is taken from following gist.
Hope this Helps!!!..
Just clear data of the Es explorer from device then after restart device.
I think these two links could help you.
firstlink
secondlink
Try to use for debug build -- targetSdkVersion 22.
After signed APK (for all targetSdkVersion(s)) application will work fine.

"Draw over other apps" change listener?

In my application I have the necessity to know when the user grants the "Draw over other apps" permission. Is there a way to know it?
Since I can only send the user to the settings page to enable it using the Settings.ACTION_MANAGE_OVERLAY_PERMISSION intent action, I'd expect a system broadcast or something like that.
Unfortunately there isn't a system broadcast, but you can use canDrawOverlays (Context context):
An app can use this method to check if it is currently allowed to draw
on top of other apps. In order to be allowed to do so, an app must
first declare the SYSTEM_ALERT_WINDOW permission in its manifest. If
it is currently disallowed, it can prompt the user to grant it this
capability through a management UI by sending an Intent with action
ACTION_MANAGE_OVERLAY_PERMISSION.
You can check it directly in your onActivityResult:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE) {
if (Settings.canDrawOverlays(this)) {
//Permission is granted
}
}
}

Using Android Drive API from Background Service

There is an example of how to use Drive API https://developers.google.com/drive/quickstart-android. It works well, but I have some trouble while trying to implement uploading file to GDrive from background service.
In all examples which I found, in case when we receive UserRecoverableAuthException we need to start new Activity using Intent from that Exception (UserRecoverableAuthException#getIntent()) to take user to the OAuth2 permission page.
When we do this from Activity, we just use startActivityForResult, and as result we can use onActivityResult to know that the user finished his interaction and we can retry.
But in case, if I want to work with Drive API from Service, and there is user interaction needed, all I can do is provide Notification to user with PendingIntent. And there is no any callback for me to know when user closes OAuth2 permission page.
Can you please suggest any approach to this? Maybe I miss something? Maybe there is some broadcast I have to catch or etc?
Thank you.
Start an activity from the notification where you'll be handling the activity result of the permission activity. Handle the result and and optionally finish the activity.
#Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (resultCode == Activity.RESULT_OK) {
// permission is given
finish();
} else {
or show error
}
}

android one time login system

I am trying to design a one time login system.
On the loginActivity the user enters a phone number to which I send a secret code thru SMS
On the confirmationActivity the user enters the secret code.
If the secret code is successful, I want to finish both confirmationActivity and loginActivity. To do that from loginActivity I do
Intent intent = new Intent(this, ConfirmationActivity.class);
startActivityForResult(intent, EXIT_CODE);
Then again in loginActivity I call
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == EXIT_CODE) {
finish();
}
}
}
To test whether my system works, after registration, I click on the back button:
Expected behavior: Not being able to go back or close the app
Actual behavior: go back to the loginActivity (notice that it skips the confirmationActivity)
My hope is that once a user successfully registers they should never again get access to either the confirmationActivity or the loginActivity. And that when they close my app and restart it, it skips those two pages and take the user directly to the home page.
Note: It looks like the onActivityResult method is never called. I place a few println calls in there and they are never printed on LogCat.
DISCLAIMER: Last time I asked a question and showed a code snippet, one respondent got distracted and started talking about the snippet instead of addressing the question. The snippet here is just to show what I have tried. Obviously it has not solved the problem. Thank you.
One possible solution could be:
Instead of opening the app with LoginActivity you create a new one called FirstActivity.
In this activity you check if you have set a flag in sharedPreferences.
If this check is true then continue to your logged-in Activity.
If this check returns false start LoginActivity. After a User has succesfully entered the "secret", you should set a flag in the sharedPreferences. Next time the user opens the app the flag in sharedPreferences will be set a you will know that the user is already registered.
Any questions? comment below

Using AuthenticatorActivity as application signin

My app requires a sync adapter and therefore requires some authentication to take place before an account can be added to the Accounts & Sync.
I have followed the sample sync adapter app and have my app setup. I can for instance now verify a user on my server and have an account added to the Accounts & Sync section.
The thing is I would prefer this precedure of adding an account via the AuthenticatorActivity to take place inside my app for a better user experience.
So far I have added the AuthenticatorActivity when my app launches. As soon as authentication is successful it launches the Accounts & Sync settings section which completely ruins the applications signin/signup experience.
How can I stop this behaviour (launch of the Accounts & Sync setting on success) and allow my app to move to my next chosen step?
It is relatively simple procedure:
Make sure instead of using startActivity you use startActivityForResult.
Intent intent = new Intent(this, ClassYouAreLaunching.class);
startActivityForResult(intent, 0); // 0 reflects the requestCode seen in onActivityResult
Then you make sure you can capture the intent once it is sent back to you from the origin intent.
onActivityResult(int requestCode, int resultCode, Intent intent) {
if( resultCode == Activity.RESULT_CANCELED ) {
finish();
} else {
// MAYBE
switch( requestCode ) {
...
}
}
}

Categories

Resources