簡體   English   中英

Android - 電話選擇器 (HintRequest) 未在雙卡手機上顯示兩個號碼

[英]Android - Phone selector (HintRequest) not showing both numbers on dual sim phone

I am using the Automatic SMS verification method for Android ( https://developers.google.com/identity/sms-retriever/request ) in Motorola One phone with Android 9 and when prompted to select the phone number, it only shows one,不是他們兩個。 我嘗試在 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 獲取號碼而編寫的完整代碼,它適用於我

公共 class 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();
}

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM