How to implement the system lock screen in your own android app

0 votes

How should the system lock screen be implemented on my own Android app, much way it is in the GooglePay, PayTM, and PFA images?enter image description here

Nov 22, 2022 in Android by Edureka
• 12,690 points
842 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

There is a feature in Android called KeyGuard. Keyguard essentially refers to the code that controls phone unlocking. It was originally created for phones with keypads.

To protect the app, Tez, Paytm, etc. employ Android's Keyguard API.

You can implement this by following the steps:

  1. Android provides KeyguardManager to implement authentication.

    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    
  2. Create an intent to request for authentication.

    Intent screenLockIntent = keyguardManager.createConfirmDeviceCredentialIntent(title, description);
    

    Here, Title and description are for displaying to user the information while authenticating. API level 21 is required for this method.

  3. You can call startActivityForResult which will return a result whether the authentication is successful.

    startActivityForResult(screenLockIntent, LOCK_REQUEST_CODE);
    

    This throws an exception if lock screen is not set up. You have to handle the situation manually.

  4. Check the result in onActivityResult

    @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
            } else {
                //Authentication failed
            }
        }
    }
answered Nov 23, 2022 by Edureka
• 13,620 points

edited Mar 5

Related Questions In Android

0 votes
0 answers

How to open WhatsApp using an Intent in your Android App?

I want an Intent to take control ...READ MORE

Nov 23, 2022 in Android by Ashwini
• 5,430 points
3,215 views
0 votes
0 answers
0 votes
1 answer
0 votes
0 answers
0 votes
1 answer

Android in-app billing - How to handle refunds ?

Simply disregard the library's purchase to overcome ...READ MORE

answered Nov 10, 2022 in Android by Edureka
• 12,690 points
1,712 views
0 votes
0 answers

How to get the device's IMEI/ESN programmatically in android?

I want to use the IMEI to ...READ MORE

Nov 16, 2022 in Android by Edureka
• 12,690 points
1,406 views
0 votes
1 answer

Running docker on Android

According to the documentation, the Android kernel is ...READ MORE

answered Aug 1, 2018 in Docker by Kalgi
• 52,350 points
3,954 views
0 votes
1 answer

Task Canceled Exception while invoking AWS Lambda

I'm guessing either the TaskCanceledException instance is ...READ MORE

answered Sep 19, 2018 in AWS by Priyaj
• 58,020 points
2,602 views
0 votes
1 answer

Is there a way to run Python on Android?

YES! here’s a barcode scanner written in six ...READ MORE

answered Sep 19, 2018 in Python by Priyaj
• 58,020 points
1,138 views
0 votes
1 answer

How can we get the current location in Android?

First you need to define a LocationListener to handle ...READ MORE

answered Sep 25, 2018 in Java by Parth
• 4,640 points
1,015 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP