Reputation: 355
in android app basic functions work fine, but the "Automate reading the SMS pin" function noted in the document is not working.
Upvotes: -6
Views: 254
Reputation: 117
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.
Upvotes: 2
Reputation: 12372
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"/>
Upvotes: 0