Automate Reading the SMS Pin not work in digits android

263 views Asked by At

in android app basic functions work fine, but the "Automate reading the SMS pin" function noted in the document is not working.

fabric-digits

2

There are 2 answers

1
Priyank Patel On

As per Document, you need to add RECEIVE_SMS permission to enable Automate Reading the SMS Pin.

Adding the permission below, in the AndroidManifest.xml, allows Digits to read the SMS pin therefore making the login process easier.

<uses-permission android:name="android.permission.RECEIVE_SMS"/>
1
Shubhendra On

First, add SMS permission in your manifest file.

<uses-permission android:name="android.permission.RECEIVE_SMS" />

Then, declare the runtime permission at the time of Login or Use my phone number activity. Add this method to your LoginActivity.class.

public static class UtilitiesPhone {
    public static final int MY_PERMISSIONS_REQUEST_READ_PHONE_STATE = 130;

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    public static boolean checkPermission(final Context context) {
        int currentAPIVersion = Build.VERSION.SDK_INT;
        if(currentAPIVersion>=android.os.Build.VERSION_CODES.M) {

            int permissionPHONE = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE);
            int permissionSMS = ContextCompat.checkSelfPermission(context, Manifest.permission.SEND_SMS);

            List<String> listPermissionsNeeded = new ArrayList<>();
            if (permissionPHONE != PackageManager.PERMISSION_GRANTED) {
                listPermissionsNeeded.add(Manifest.permission.READ_PHONE_STATE);
            }
            if (permissionSMS != PackageManager.PERMISSION_GRANTED) {
                listPermissionsNeeded.add(Manifest.permission.SEND_SMS);
            }
            if (!listPermissionsNeeded.isEmpty()) {
                ActivityCompat.requestPermissions((Activity) context,
                        listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), MY_PERMISSIONS_REQUEST_READ_PHONE_STATE);
                return false;
            }
        }else{
            return true;
        }

        return true;
    }
}

declare this in your onCreate

final boolean result= LoginActivity.UtilitiesPhone.checkPermission(this);

And done. Now the autofill works like charm.

Note that you can choose to keep the phone state permission or just remove it.