我已经在我的项目中实现了电话号码选择器API,现在我想检查输入的号码是否存在于移动中?只有当设备具有输入的号码时,它才应该继续。而且数字应该插入第一个插槽。如何做到这一点?
这是我的代码:
HintRequest hintRequest = new HintRequest.Builder()
.setHintPickerConfig(
new CredentialPickerConfig.Builder().setShowCancelButton(true).build()
)
.setPhoneNumberIdentifierSupported(true)
.build();
PendingIntent intent = Credentials.getClient(Register.this).getHintPickerIntent(hintRequest);
try {
startIntentSenderForResult(intent.getIntentSender(),CREDENTIAL_REQUEST,null,0,0,0,new Bundle());
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
enterNumber = findViewById(R.id.renter_number);
rback_btn = findViewById(R.id.rback_btn);
rback_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
Intent i = new Intent(getApplicationContext(), Welcome.class);
startActivity(i);
}
});
next = findViewById(R.id.nextbtn_r);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
strnumber = enterNumber.getText().toString();
String otp= new DecimalFormat("000000").format(new Random().nextInt(999999));
Intent intent = new Intent(getApplicationContext(), Verification.class);
intent.putExtra("Your OTP is:",otp);
intent.putExtra("Number:",strnumber);
startActivity(intent);
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CREDENTIAL_REQUEST && resultCode == RESULT_OK) {
//obtain the phone number from the result
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
enterNumber.setText(credential.getId().substring(3));
Toast
.makeText(context, "Mob"+credential.getId().substring(3), Toast.LENGTH_SHORT)
.show();
} else if (
requestCode == CREDENTIAL_REQUEST
&& requestCode == CredentialsApi.ACTIVITY_RESULT_NO_HINTS_AVAILABLE
) {
Toast
.makeText(context, "No Phone Numbers found!", Toast.LENGTH_SHORT)
.show();
}
}
在Android上无法获取电话号码。有一种方法:
TelephonyManager mgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = mgr.getLine1Number();
只有在获得许可的情况下才能工作:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
但现在的SIM卡并不可靠。。。事实上大多数设备将返回CCD_ 1。您可以在系统设置中检查此项->关于->电话标识(或电话号码(
请注意,SIM卡本身确实有一些身份参数,比如序列号,但它并没有存储自己的号码,而是连接到网络侧的SIM卡上。这就是为什么大多数电话号码验证服务都要求输入电话号码,然后发送短信,并要求重新编写代码(或者你可以通过编程来完成——在请求验证短信发送后,只需在接下来的几秒/分钟内检查传入的短信,你需要获得许可(