gpt4 book ai didi

java - Android - 手机选择器 (HintRequest) 在双 SIM 卡手机上不显示两个号码

转载 作者:行者123 更新时间:2023-12-01 21:25:53 25 4
gpt4 key购买 nike

我在装有 Android 9 的 Motorola One 手机中使用 Android 自动短信验证方法 ( https://developers.google.com/identity/sms-retriever/request ),当提示选择电话号码时,它只显示一个,而不是两个。我尝试在 Google 上查找此内容,但没有发现任何类似内容。

我的代码测试是:

    HintRequest hintRequest = new HintRequest.Builder()
.setPhoneNumberIdentifierSupported(true)
.build();

GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Auth.CREDENTIALS_API)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.i(TAG_LOG, "google api connected");
}

@Override
public void onConnectionSuspended(int i) {
Log.i(TAG_LOG, "google api suspended: " + i);
}
})
.enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.i(TAG_LOG, "google api connect failed: " );
}
})
.build();

PendingIntent intent = Auth.CredentialsApi.getHintPickerIntent(
mGoogleApiClient, hintRequest);
try {
startIntentSenderForResult(intent.getIntentSender(),
RESOLVE_HINT, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}

有什么想法吗?

最佳答案

这是我编写的使用 googleapiclient API 获取号码的完整代码,它对我有用

公共(public)类 MobileNumberActivity 扩展 AppCompatActivity 实现 View.OnClickListener、GoogleApiClient.ConnectionCallbacks、GoogleApiClient.OnConnectionFailedListener {

private String mob;
EditText etMobileNumber;
TypedInput input;
ViewDialog viewDialog;
String TOKEN = "token";
GoogleApiClient apiClient;
int RC_HINT = 1008;
SharedPreferences sharedpreferences;
Intent i;
String intenString;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mobile_number);


i = getIntent();

intenString = i.getStringExtra("google_login");


sharedpreferences = getSharedPreferences(TOKEN, Context.MODE_PRIVATE);

etMobileNumber = findViewById(R.id.etPhoneNumber);

mob = etMobileNumber.getText().toString();

Button send_otp = findViewById(R.id.continue_button);
send_otp.setOnClickListener(this);
viewDialog = new ViewDialog(MobileNumberActivity.this);


getCreadenticalApiClient();
showHint();


}

@Override
public void onClick(View v) {


if (v.getId() == R.id.continue_button) {
if (etMobileNumber.getText().toString().trim().length() == 0) {
Toasty.error(MobileNumberActivity.this, "Please Enter Mobile Number", Toast.LENGTH_SHORT, true).show();

} else if (etMobileNumber.getText().toString().trim().length() < 10) {
Toasty.error(MobileNumberActivity.this, "Please Enter Valid Mobile Number", Toast.LENGTH_SHORT, true).show();

} else {

if (getIntent().getExtras()!=null) {
try {

JSONObject object = new JSONObject();
object.put("mb", etMobileNumber.getText().toString());
object.put("token", Constant.token);

input = new TypedByteArray("application/json", object.toString().getBytes());

Log.d("tmz", object.toString());
if (Network.isConnectedToNetwork(MobileNumberActivity.this)) {

phoneLoginApi();
} else {
Toasty.error(MobileNumberActivity.this, "Please Connect To Internet!", Toast.LENGTH_SHORT, true).show();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
finish();
}


} catch (Exception e) {

e.printStackTrace();
}

}else{
try {

JSONObject object = new JSONObject();
object.put("mb", etMobileNumber.getText().toString());

input = new TypedByteArray("application/json", object.toString().getBytes());

Log.d("tmz", object.toString());
if (Network.isConnectedToNetwork(MobileNumberActivity.this)) {

phoneLoginApi();
} else {
Toasty.error(MobileNumberActivity.this, "Please Connect To Internet!", Toast.LENGTH_SHORT, true).show();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
finish();
}


} catch (Exception e) {

e.printStackTrace();
}
}


}
}

}


private void phoneLoginApi() {
viewDialog.showDialog();

RequestInterceptor requestInterceptor = new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
request.addHeader("Content-Type", "application/json");
request.addHeader("Connection", "close");
}
};

RestAdapter restAdapter = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.FULL)
.setRequestInterceptor(requestInterceptor)
.setEndpoint(Constant.Server_Url)
.build();


PostInterfaces api = restAdapter.create(PostInterfaces.class);

api.signinwithMobile(input, new Callback<Response>() {
@Override
public void success(Response result, Response response) {

BufferedReader reader;
String output;

try {
reader = new BufferedReader(new InputStreamReader(result.getBody().in()));
output = reader.readLine();
JSONObject object = new JSONObject(output);
String response_string = object.getString("status");
Constant.token = object.getString("token");
Constant.message = object.getString("message");


if (response_string.equals("0")) {

viewDialog.hideDialog();
startActivity(new Intent(MobileNumberActivity.this, OtpActivity.class));
overridePendingTransition(R.anim.push_in_to_left, R.anim.push_in_to_right);
finish();

}
// Test Pending //
else if (response_string.equals("1")) {
viewDialog.hideDialog();
startActivity(new Intent(MobileNumberActivity.this, OtpActivity.class));
overridePendingTransition(R.anim.push_in_to_left, R.anim.push_in_to_right);
finish();


}

} catch (Exception e) {

Toast.makeText(MobileNumberActivity.this, "Error: " + e.toString(), Toast.LENGTH_SHORT).show();
}

}

@Override
public void failure(RetrofitError error) {

Toast.makeText(MobileNumberActivity.this, error.toString(), Toast.LENGTH_SHORT).show();

}
});


}

**private void showHint() {
HintRequest hintRequest = new HintRequest.Builder()
.setHintPickerConfig(new CredentialPickerConfig.Builder()
.setShowCancelButton(true)
.build())
.setPhoneNumberIdentifierSupported(true)
.build();
PendingIntent intent =
Auth.CredentialsApi.getHintPickerIntent(apiClient, hintRequest);
try {
startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0, new Bundle());
} catch (IntentSender.SendIntentException e) {
Log.e("Login", "Could not start hint picker Intent", e);
}
}
private void getCreadenticalApiClient() {
apiClient = new GoogleApiClient.Builder(getBaseContext())
.addConnectionCallbacks(this)
.enableAutoManage(MobileNumberActivity.this, this)
.addApi(Auth.CREDENTIALS_API)
.build();
}**

@Override
public void onConnected(@Nullable Bundle bundle) {

}

@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

}

**@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_HINT) {
if (resultCode == RESULT_OK) {
assert data != null;
Credential cred = data.getParcelableExtra(Credential.EXTRA_KEY);
etMobileNumber.setText(cred.getId().substring(3));
}
}
}**

@Override
public void onBackPressed() {
super.onBackPressed();
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.clear();
editor.apply();
}

}

关于java - Android - 手机选择器 (HintRequest) 在双 SIM 卡手机上不显示两个号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58833146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com