Skip to content
Advertisement

java.lang.IllegalArgumentException: Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, ortemprary proof

This Exception is taking place in my code help please. my all code is posted below.

java.lang.IllegalArgumentException: Cannot create PhoneAuthCredential
without either verificationProof, sessionInfo, ortemprary proof.
        at com.google.android.gms.common.internal.Preconditions.checkArgument(Unknown
Source)
        at com.google.firebase.auth.PhoneAuthCredential.<init>(Unknown Source)
        at com.google.firebase.auth.PhoneAuthProvider.getCredential(Unknown
Source)
        at com.approsoft.momentsapp.providerfrags.EnterPhoneFragment$3.onVerificationCompleted(EnterPhoneFragment.java:177)
        at com.google.firebase.auth.api.internal.zzer.zza(Unknown Source)
        at com.google.firebase.auth.api.internal.zzeu.run(Unknown Source)
        at android.os.Handler.handleCallback(Handler.java:815)
        at android.os.Handler.dispatchMessage(Handler.java:104)
        at android.os.Looper.loop(Looper.java:238)
        at android.app.ActivityThread.main(ActivityThread.java:6006)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:937)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:798)

How to resolve this issue before I updated ui version 4.0.1 to 4.2.0 and also update 4.3.1 but not resolve this issue

I have passed too many days on this issue but not resolve please help .

Here is my code

public class EnterPhoneFragment extends Fragment {

Button btnSendCode, btnVerify, btnResendCode;
EditText etCode;
IntlPhoneInput etPhoneNumber;
TextView tvTerms;

PhoneAuthProvider.OnVerificationStateChangedCallbacks verificationCallbacks;
PhoneAuthProvider.ForceResendingToken resendingToken;
FirebaseAuth firebaseAuth;

String phoneVerificationID;
HashMap<String, String> userDetails;
String userID;

private static final long TIMEOUT_DURATION = 60;

SessionManager sessionManager;
FragmentManager fragmentManager;
private MaterialDialog dialogSave;
private String smsCode;
private PhoneAuthCredential credential;

public EnterPhoneFragment() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_enter_phone, container, false);
    sessionManager = new SessionManager(getActivity());
    userDetails = sessionManager.getUserDetails();
    userID = userDetails.get(SessionManager.KEY_USER_ID);
    fragmentManager = getFragmentManager();

    firebaseAuth = FirebaseAuth.getInstance();
    setUpVerificationCallbacks();
    tvTerms = view.findViewById(R.id.tvTerms);
    String termsString = "<u><b>Terms of Service</b></u>";
    tvTerms.setText(Html.fromHtml(termsString));
    etPhoneNumber = view.findViewById(R.id.etPhoneNumber);

    etCode = view.findViewById(R.id.etCode);
    etCode.setEnabled(false);

    btnResendCode = view.findViewById(R.id.btnResendCode);
    btnResendCode.setEnabled(false);

    dialogSave = new MaterialDialog.Builder(getActivity())
            .title("Sending")
            .content("Please wait")
            .cancelable(false)
            .progress(true, 0).build();

    btnVerify = view.findViewById(R.id.btnVerify);
    btnVerify.setEnabled(false);
    btnVerify.setBackgroundColor(getResources().getColor(R.color.colorGrey));
    btnVerify.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String code = etCode.getText().toString();
            if (TextUtils.isEmpty(code)) {
                etCode.setError("Enter smsCode first");
                etCode.requestFocus();
            } else {
                if (smsCode.equals(code)) {
                    signInWithPhoneCredential(credential);
                } else {
                    Toast.makeText(getActivity(), "Enter a valid code!", Toast.LENGTH_SHORT).show();
                }
            }
        }
    });

    btnSendCode = view.findViewById(R.id.btnSendCode);
    btnSendCode.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String phoneNumber;
            if (etPhoneNumber.isValid()) {
                phoneNumber = etPhoneNumber.getNumber();
                verifyPhoneNumber(phoneNumber);

            } else {
                Toast.makeText(getActivity().getApplicationContext(), "Enter a valid phone number!", Toast.LENGTH_SHORT).show();
            }
        }
    });
    saveSetting();
    return view;
}

@Override
public void onResume() {
    super.onResume();
}

@Override
public void onPause() {
    super.onPause();
}
public void verifyPhoneNumber(String phoneNumber){
    PhoneAuthProvider.getInstance().verifyPhoneNumber(
            phoneNumber,
            60,
            TimeUnit.SECONDS,
            getActivity(),
            verificationCallbacks);
}

private void setUpVerificationCallbacks() {
    try {
        verificationCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
            @Override
            public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
                //signInWithPhoneCredential(phoneAuthCredential);
                smsCode = phoneAuthCredential.getSmsCode();
                credential = PhoneAuthProvider.getCredential(phoneVerificationID, smsCode);
            }

            @Override
            public void onVerificationFailed(FirebaseException e) {
                if (e instanceof FirebaseAuthInvalidCredentialsException) {
                    Toast.makeText(getActivity().getApplicationContext(), "Invalid credentials used. Try again!", Toast.LENGTH_SHORT).show();
                } else if (e instanceof FirebaseTooManyRequestsException) {
                    Toast.makeText(getActivity().getApplicationContext(), "SMS Quota expired. Come back later.", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
                phoneVerificationID = s;
                resendingToken = forceResendingToken;
                etPhoneNumber.setEnabled(false);
                btnSendCode.setEnabled(false);
                etCode.setEnabled(true);
                btnVerify.setEnabled(true);
                btnVerify.setBackgroundColor(getResources().getColor(R.color.colorIndigoBlue));
                btnResendCode.setEnabled(true);
            }
        };
    } catch (Exception ex) {
        Log.i("IllegalState", "Exception is Illegal state exception");
    }
}

private void signInWithPhoneCredential(PhoneAuthCredential credential) {
    firebaseAuth.signInWithCredential(credential)
            .addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        FirebaseUser user = task.getResult().getUser();
                        final String userPhone = user.getPhoneNumber();
                        RequestQueue queue = Volley.newRequestQueue(getActivity());
                        try {
                            dialogSave.show();

                            // Request a string response from the provided URL.
                            StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.url + "save_phone.php",
                                    new Response.Listener<String>() {
                                        @Override
                                        public void onResponse(String result) {
                                            if (!dialogSave.isCancelled()) {
                                                dialogSave.dismiss();
                                            }
                                            if (result.equals("Error")) {
                                                Toast.makeText(getActivity(), "userId and mobile are not empty!", Toast.LENGTH_SHORT).show();
                                            }
                                            if (result.equals("this mobile number already exist!")) {
                                                Toast.makeText(getActivity(), "this mobile number already exist!", Toast.LENGTH_SHORT).show();
                                            } else {
                                                try {
                                                    JSONObject response = new JSONObject(result);
                                                    String userEmail = response.getString("email");
                                                    if (userEmail != null && !userEmail.isEmpty()) {
                                                        String userID = response.getString("id");
                                                        String fbID = response.getString("fb_id");
                                                        String googleID = response.getString("google_id");
                                                        String firstName = response.getString("first_name");
                                                        String lastName = response.getString("last_name");
                                                        String userPass = response.getString("password");
                                                        String userMobile = response.getString("mobile");
                                                        String userLocation = response.getString("location");
                                                        String userDOB = response.getString("dob");
                                                        String userGender = response.getString("gender");
                                                        String posts = response.getString("posts");
                                                        String following = response.getString("following");
                                                        String followers = response.getString("followers");
                                                        String userImagePath = "http://fotogher.com/app/Moments/provider/" + response.getString("image_path");
                                                        sessionManager.createLoginSession(userID, userEmail, fbID, googleID,
                                                                firstName, lastName, userPass, userMobile, userLocation,
                                                                userDOB, userGender, userImagePath, posts, following, followers);
                                                        for (int i = 0; i < fragmentManager.getBackStackEntryCount(); i++) {
                                                            fragmentManager.popBackStack();
                                                        }
                                                        startActivity(new Intent(getActivity(), MainActivity.class));
                                                        getActivity().finish();
                                                    } else {
                                                        Toast.makeText(getActivity().getApplicationContext(),
                                                                "Profile creation failed. Try again!",
                                                                Toast.LENGTH_SHORT).show();
                                                    }
                                                } catch (JSONException e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        }
                                    }, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
                                    if (!dialogSave.isCancelled()) {
                                        dialogSave.dismiss();
                                    }
                                    Toast.makeText(getActivity(), "Error!", Toast.LENGTH_SHORT).show();
                                }

                            }) {
                                @Override
                                protected Map<String, String> getParams() {
                                    Map<String, String> params = new HashMap<String, String>();
                                    params.put("mobile", userPhone);
                                    params.put("user_id", userID);
                                    return params;
                                }

                                @Override
                                public Map<String, String> getHeaders() throws AuthFailureError {
                                    Map<String, String> params = new HashMap<String, String>();
                                    params.put("Content-Type", "application/x-www-form-urlencoded");
                                    return params;
                                }
                            };
                            // Add the request to the RequestQueue.
                            queue.add(stringRequest);
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }

                    } else {
                        if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                            // The verification smsCode entered was invalid
                            Log.i("Exception","Invalid smsCode entered. Try again!");
                        }
                    }
                }
            });
}

my gradle file is this

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.approsoft.momentsapp"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 2
        versionName "0.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    mavenCentral()
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    /*implementation 'com.android.support:appcompat-v7:26.1.0'*/
    implementation 'com.android.support:design:27.1.1'
    /*implementation 'com.android.support.constraint:constraint-layout:1.0.2'*/
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.google.firebase:firebase-database:16.1.0'
    implementation 'com.google.firebase:firebase-analytics:16.3.0'
    implementation 'com.google.firebase:firebase-auth:16.1.0'
    implementation 'com.google.firebase:firebase-messaging:17.4.0'
    implementation 'com.google.android.gms:play-services-places:16.0.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.firebaseui:firebase-ui-auth:4.2.0'
    implementation 'com.facebook.android:facebook-android-sdk:4.29.0'
    implementation 'com.github.ittianyu:BottomNavigationViewEx:1.2.4'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'com.wonderkiln:camerakit:0.13.2'
    implementation 'com.camerakit:jpegkit:0.1.0'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0'
//    compile 'com.github.yalantis:ucrop:2.2.1'
    implementation 'com.github.bumptech.glide:glide:4.6.1'
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
/*    implementation 'com.hbb20:ccp:2.2.3'*/
    implementation 'com.github.mukeshsolanki:country-picker-android:2.0.1'
    implementation 'hani.momanii.supernova_emoji_library:supernova-emoji-library:0.0.2'
    //for video view
    //implementation 'com.github.halilozercan:BetterVideoPlayer:kotlin-SNAPSHOT'
    implementation 'com.android.volley:volley:1.1.1'
    //implementation 'com.github.hani-momanii:SuperNova-Emoji:1.1'
    //implementation project(':supernova-emoji-library')
//    compile 'id.zelory:compressor:2.1.0'
    implementation 'net.rimoto:intlphoneinput:1.0.1'
    implementation 'com.github.zcweng:switch-button:0.0.3@aar'
    implementation 'com.bikomobile:multipart:1.3.4'
    implementation 'com.github.shts:StoriesProgressView:3.0.0'
    implementation('com.mapbox.mapboxsdk:mapbox-android-sdk:6.5.0@aar') {
        transitive = true
    }
    implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.19.0'
    implementation('com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.19.0') {
        transitive = true
    }
    implementation 'com.android.support:multidex:1.0.3'
//    testImplementation 'junit:junit:4.12'
//    androidTestImplementation 'com.android.support.test:runner:1.0.1'
//    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

apply plugin: 'com.google.gms.google-services'

Advertisement

Answer

Add your SHA code on firebase settings to your project. If already done, do the same again with the recent one. It worked for me.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement