SMS authentication on android NullPointerException
I'm getting this error
Updated error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxx.com.xxx, PID: 4963
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task
com.google.android.gms.common.api.GoogleApi.zzb(com.google.android.gms.common.api.internal.zzdf)'
on a null object reference
at com.google.android.gms.internal.zzdtp.zzb(Unknown Source)
at com.google.android.gms.internal.zzdtw.zza(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.zza(Unknown Source)
at com.google.firebase.auth.PhoneAuthProvider.zza(Unknown Source)
at com.google.firebase.auth.PhoneAuthProvider.verifyPhoneNumber(Unknown
Source)
at xxx.com.xxx.PhoneNumberActivity.onClick(PhoneNumberActivity.java:110)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
When I try to run this code
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallbacks
In app build.gradle
implementation 'com.google.firebase:firebase-database:11.6.0'
implementation 'com.google.firebase:firebase-auth:11.6.0'
Why is it saying it's null? What is null? I'm running it on android device Android version 6.0. Is it because there's no sim card on the phone? I've already enabled phone authentication in the console and it's working on iOS.
Updates:
After Updating the version of firebase-core and firebasse-auth, the app doesn't crash any more.
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
Found out it's caused by version 8.3.01 (2385995-434) Google Play services of the phone I'm testing on. Any solution to make it work with 8.3.01?
Error:
" W/GooglePlayServicesUtil: Google Play services out of date.
Requires 12451000 but found 8301434"
Question:
How to control the min Google Play services version?
android firebase-authentication
add a comment |
I'm getting this error
Updated error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxx.com.xxx, PID: 4963
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task
com.google.android.gms.common.api.GoogleApi.zzb(com.google.android.gms.common.api.internal.zzdf)'
on a null object reference
at com.google.android.gms.internal.zzdtp.zzb(Unknown Source)
at com.google.android.gms.internal.zzdtw.zza(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.zza(Unknown Source)
at com.google.firebase.auth.PhoneAuthProvider.zza(Unknown Source)
at com.google.firebase.auth.PhoneAuthProvider.verifyPhoneNumber(Unknown
Source)
at xxx.com.xxx.PhoneNumberActivity.onClick(PhoneNumberActivity.java:110)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
When I try to run this code
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallbacks
In app build.gradle
implementation 'com.google.firebase:firebase-database:11.6.0'
implementation 'com.google.firebase:firebase-auth:11.6.0'
Why is it saying it's null? What is null? I'm running it on android device Android version 6.0. Is it because there's no sim card on the phone? I've already enabled phone authentication in the console and it's working on iOS.
Updates:
After Updating the version of firebase-core and firebasse-auth, the app doesn't crash any more.
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
Found out it's caused by version 8.3.01 (2385995-434) Google Play services of the phone I'm testing on. Any solution to make it work with 8.3.01?
Error:
" W/GooglePlayServicesUtil: Google Play services out of date.
Requires 12451000 but found 8301434"
Question:
How to control the min Google Play services version?
android firebase-authentication
Reason for downvoting please
– user1872384
Nov 19 '18 at 7:49
Is it because there's no sim card on the phone? -> No. I'm using without SIM and it's working. and what variable you are gettingnull?
– Rumit Patel
Nov 19 '18 at 9:26
@RumitPatel I've updated the full error code when PhoneAuthProvider.getInstance().verifyPhoneNumber is called. I'm wondering what's the root cause for the app to crash as well.
– user1872384
Nov 19 '18 at 9:49
updatecom.google.gms:google-services
,com.google.firebase:firebase-core
, andcom.google.firebase:firebase-auth
to the latest and try.
– Rumit Patel
Nov 19 '18 at 10:05
I'm using these: classpath 'com.google.gms:google-services:4.1.0' implementation 'com.google.firebase:firebase-database:11.6.0' implementation 'com.google.firebase:firebase-auth:11.6.0' Is it not compatible? is there a list showing which version of com.google.gms:google-services is compatible with com.google.firebase:? It's rather confusing
– user1872384
Nov 22 '18 at 9:47
add a comment |
I'm getting this error
Updated error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxx.com.xxx, PID: 4963
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task
com.google.android.gms.common.api.GoogleApi.zzb(com.google.android.gms.common.api.internal.zzdf)'
on a null object reference
at com.google.android.gms.internal.zzdtp.zzb(Unknown Source)
at com.google.android.gms.internal.zzdtw.zza(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.zza(Unknown Source)
at com.google.firebase.auth.PhoneAuthProvider.zza(Unknown Source)
at com.google.firebase.auth.PhoneAuthProvider.verifyPhoneNumber(Unknown
Source)
at xxx.com.xxx.PhoneNumberActivity.onClick(PhoneNumberActivity.java:110)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
When I try to run this code
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallbacks
In app build.gradle
implementation 'com.google.firebase:firebase-database:11.6.0'
implementation 'com.google.firebase:firebase-auth:11.6.0'
Why is it saying it's null? What is null? I'm running it on android device Android version 6.0. Is it because there's no sim card on the phone? I've already enabled phone authentication in the console and it's working on iOS.
Updates:
After Updating the version of firebase-core and firebasse-auth, the app doesn't crash any more.
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
Found out it's caused by version 8.3.01 (2385995-434) Google Play services of the phone I'm testing on. Any solution to make it work with 8.3.01?
Error:
" W/GooglePlayServicesUtil: Google Play services out of date.
Requires 12451000 but found 8301434"
Question:
How to control the min Google Play services version?
android firebase-authentication
I'm getting this error
Updated error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxx.com.xxx, PID: 4963
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task
com.google.android.gms.common.api.GoogleApi.zzb(com.google.android.gms.common.api.internal.zzdf)'
on a null object reference
at com.google.android.gms.internal.zzdtp.zzb(Unknown Source)
at com.google.android.gms.internal.zzdtw.zza(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.zza(Unknown Source)
at com.google.firebase.auth.PhoneAuthProvider.zza(Unknown Source)
at com.google.firebase.auth.PhoneAuthProvider.verifyPhoneNumber(Unknown
Source)
at xxx.com.xxx.PhoneNumberActivity.onClick(PhoneNumberActivity.java:110)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
When I try to run this code
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallbacks
In app build.gradle
implementation 'com.google.firebase:firebase-database:11.6.0'
implementation 'com.google.firebase:firebase-auth:11.6.0'
Why is it saying it's null? What is null? I'm running it on android device Android version 6.0. Is it because there's no sim card on the phone? I've already enabled phone authentication in the console and it's working on iOS.
Updates:
After Updating the version of firebase-core and firebasse-auth, the app doesn't crash any more.
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
Found out it's caused by version 8.3.01 (2385995-434) Google Play services of the phone I'm testing on. Any solution to make it work with 8.3.01?
Error:
" W/GooglePlayServicesUtil: Google Play services out of date.
Requires 12451000 but found 8301434"
Question:
How to control the min Google Play services version?
android firebase-authentication
android firebase-authentication
edited Nov 30 '18 at 6:51
user1872384
asked Nov 19 '18 at 7:36
user1872384user1872384
4,18553262
4,18553262
Reason for downvoting please
– user1872384
Nov 19 '18 at 7:49
Is it because there's no sim card on the phone? -> No. I'm using without SIM and it's working. and what variable you are gettingnull?
– Rumit Patel
Nov 19 '18 at 9:26
@RumitPatel I've updated the full error code when PhoneAuthProvider.getInstance().verifyPhoneNumber is called. I'm wondering what's the root cause for the app to crash as well.
– user1872384
Nov 19 '18 at 9:49
updatecom.google.gms:google-services
,com.google.firebase:firebase-core
, andcom.google.firebase:firebase-auth
to the latest and try.
– Rumit Patel
Nov 19 '18 at 10:05
I'm using these: classpath 'com.google.gms:google-services:4.1.0' implementation 'com.google.firebase:firebase-database:11.6.0' implementation 'com.google.firebase:firebase-auth:11.6.0' Is it not compatible? is there a list showing which version of com.google.gms:google-services is compatible with com.google.firebase:? It's rather confusing
– user1872384
Nov 22 '18 at 9:47
add a comment |
Reason for downvoting please
– user1872384
Nov 19 '18 at 7:49
Is it because there's no sim card on the phone? -> No. I'm using without SIM and it's working. and what variable you are gettingnull?
– Rumit Patel
Nov 19 '18 at 9:26
@RumitPatel I've updated the full error code when PhoneAuthProvider.getInstance().verifyPhoneNumber is called. I'm wondering what's the root cause for the app to crash as well.
– user1872384
Nov 19 '18 at 9:49
updatecom.google.gms:google-services
,com.google.firebase:firebase-core
, andcom.google.firebase:firebase-auth
to the latest and try.
– Rumit Patel
Nov 19 '18 at 10:05
I'm using these: classpath 'com.google.gms:google-services:4.1.0' implementation 'com.google.firebase:firebase-database:11.6.0' implementation 'com.google.firebase:firebase-auth:11.6.0' Is it not compatible? is there a list showing which version of com.google.gms:google-services is compatible with com.google.firebase:? It's rather confusing
– user1872384
Nov 22 '18 at 9:47
Reason for downvoting please
– user1872384
Nov 19 '18 at 7:49
Reason for downvoting please
– user1872384
Nov 19 '18 at 7:49
Is it because there's no sim card on the phone? -> No. I'm using without SIM and it's working. and what variable you are getting
null?
– Rumit Patel
Nov 19 '18 at 9:26
Is it because there's no sim card on the phone? -> No. I'm using without SIM and it's working. and what variable you are getting
null?
– Rumit Patel
Nov 19 '18 at 9:26
@RumitPatel I've updated the full error code when PhoneAuthProvider.getInstance().verifyPhoneNumber is called. I'm wondering what's the root cause for the app to crash as well.
– user1872384
Nov 19 '18 at 9:49
@RumitPatel I've updated the full error code when PhoneAuthProvider.getInstance().verifyPhoneNumber is called. I'm wondering what's the root cause for the app to crash as well.
– user1872384
Nov 19 '18 at 9:49
update
com.google.gms:google-services
, com.google.firebase:firebase-core
, and com.google.firebase:firebase-auth
to the latest and try.– Rumit Patel
Nov 19 '18 at 10:05
update
com.google.gms:google-services
, com.google.firebase:firebase-core
, and com.google.firebase:firebase-auth
to the latest and try.– Rumit Patel
Nov 19 '18 at 10:05
I'm using these: classpath 'com.google.gms:google-services:4.1.0' implementation 'com.google.firebase:firebase-database:11.6.0' implementation 'com.google.firebase:firebase-auth:11.6.0' Is it not compatible? is there a list showing which version of com.google.gms:google-services is compatible with com.google.firebase:? It's rather confusing
– user1872384
Nov 22 '18 at 9:47
I'm using these: classpath 'com.google.gms:google-services:4.1.0' implementation 'com.google.firebase:firebase-database:11.6.0' implementation 'com.google.firebase:firebase-auth:11.6.0' Is it not compatible? is there a list showing which version of com.google.gms:google-services is compatible with com.google.firebase:? It's rather confusing
– user1872384
Nov 22 '18 at 9:47
add a comment |
1 Answer
1
active
oldest
votes
You can have a look at this working code.
build.gradle(app-level)
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
}
build.gradle(project-level)
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.1.0'
}
}
Activity:
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.FirebaseTooManyRequestsException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import java.util.concurrent.TimeUnit;
public class FCMsmsTest extends AppCompatActivity {
private EditText editText;
private String mVerificationId = "";
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(FCMsmsTest.this, "onVerificationCompleted " + phoneAuthCredential.toString(), Toast.LENGTH_SHORT).show();
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(FCMsmsTest.this, "onVerificationFailed " + e.toString(), Toast.LENGTH_SHORT).show();
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(FCMsmsTest.this, "Invalid Request " + e.toString(), Toast.LENGTH_SHORT).show();
} else if (e instanceof FirebaseTooManyRequestsException) {
Toast.makeText(FCMsmsTest.this, "The SMS quota for the project has been exceeded " + e.toString(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
Toast.makeText(FCMsmsTest.this, "onCodeSent " + verificationId, Toast.LENGTH_SHORT).show();
editText.setText("");
mVerificationId = verificationId;
PhoneAuthProvider.ForceResendingToken mResendToken = token;
showDialog();
}
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fcm_sms_test);
editText = findViewById(R.id.edit_text);
findViewById(R.id.btn_send_sms).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (editText.getText().toString().trim().length() > 9) {
sendSMS("+91" + editText.getText().toString().trim());
} else {
Toast.makeText(FCMsmsTest.this, "Enter Valid PhoneNumber", Toast.LENGTH_SHORT).show();
}
}
});
}
private void sendSMS(String phoneNumber) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks);
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(FCMsmsTest.this, "signInWithCredential:success", Toast.LENGTH_SHORT).show();
FirebaseUser user = task.getResult().getUser();
} else {
Toast.makeText(FCMsmsTest.this, "signInWithCredential:failure", Toast.LENGTH_SHORT).show();
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(FCMsmsTest.this, "The verification code entered was invalid", Toast.LENGTH_SHORT).show();
}
}
}
});
}
private void showDialog() {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
final EditText edittextCode = new EditText(FCMsmsTest.this);
alert.setMessage("Enter Your Message");
alert.setTitle("Enter Your Title");
alert.setView(edittextCode);
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String YouEditTextValueString = edittextCode.getText().toString();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, YouEditTextValueString);
signInWithPhoneAuthCredential(credential);
}
});
alert.show();
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="50dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+91" />
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone" />
</TableRow>
<Button
android:id="@+id/btn_send_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Send OTP" />
</LinearLayout>
Update your project accordingly.
@user1872384 have you checked it out?
– Rumit Patel
Nov 27 '18 at 10:38
Rumit Patel, I've tried to upgrade the version but still doesn't receive an sms
– user1872384
Nov 27 '18 at 14:04
have you tried as in answer?
– Rumit Patel
Nov 27 '18 at 14:09
I've found out that the phone I'm using is having version 8.3.01 (2385995-434) Google Play services which might be the root cause, are there any documentation stating that it must be higher than version 9.0.0? According to this answer stackoverflow.com/questions/43422021/…
– user1872384
Nov 30 '18 at 6:20
However in the error logs it states that I need version "12.4.51.000" instead of "8.3.01.434"
– user1872384
Nov 30 '18 at 6:46
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370161%2fsms-authentication-on-android-nullpointerexception%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can have a look at this working code.
build.gradle(app-level)
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
}
build.gradle(project-level)
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.1.0'
}
}
Activity:
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.FirebaseTooManyRequestsException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import java.util.concurrent.TimeUnit;
public class FCMsmsTest extends AppCompatActivity {
private EditText editText;
private String mVerificationId = "";
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(FCMsmsTest.this, "onVerificationCompleted " + phoneAuthCredential.toString(), Toast.LENGTH_SHORT).show();
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(FCMsmsTest.this, "onVerificationFailed " + e.toString(), Toast.LENGTH_SHORT).show();
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(FCMsmsTest.this, "Invalid Request " + e.toString(), Toast.LENGTH_SHORT).show();
} else if (e instanceof FirebaseTooManyRequestsException) {
Toast.makeText(FCMsmsTest.this, "The SMS quota for the project has been exceeded " + e.toString(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
Toast.makeText(FCMsmsTest.this, "onCodeSent " + verificationId, Toast.LENGTH_SHORT).show();
editText.setText("");
mVerificationId = verificationId;
PhoneAuthProvider.ForceResendingToken mResendToken = token;
showDialog();
}
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fcm_sms_test);
editText = findViewById(R.id.edit_text);
findViewById(R.id.btn_send_sms).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (editText.getText().toString().trim().length() > 9) {
sendSMS("+91" + editText.getText().toString().trim());
} else {
Toast.makeText(FCMsmsTest.this, "Enter Valid PhoneNumber", Toast.LENGTH_SHORT).show();
}
}
});
}
private void sendSMS(String phoneNumber) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks);
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(FCMsmsTest.this, "signInWithCredential:success", Toast.LENGTH_SHORT).show();
FirebaseUser user = task.getResult().getUser();
} else {
Toast.makeText(FCMsmsTest.this, "signInWithCredential:failure", Toast.LENGTH_SHORT).show();
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(FCMsmsTest.this, "The verification code entered was invalid", Toast.LENGTH_SHORT).show();
}
}
}
});
}
private void showDialog() {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
final EditText edittextCode = new EditText(FCMsmsTest.this);
alert.setMessage("Enter Your Message");
alert.setTitle("Enter Your Title");
alert.setView(edittextCode);
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String YouEditTextValueString = edittextCode.getText().toString();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, YouEditTextValueString);
signInWithPhoneAuthCredential(credential);
}
});
alert.show();
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="50dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+91" />
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone" />
</TableRow>
<Button
android:id="@+id/btn_send_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Send OTP" />
</LinearLayout>
Update your project accordingly.
@user1872384 have you checked it out?
– Rumit Patel
Nov 27 '18 at 10:38
Rumit Patel, I've tried to upgrade the version but still doesn't receive an sms
– user1872384
Nov 27 '18 at 14:04
have you tried as in answer?
– Rumit Patel
Nov 27 '18 at 14:09
I've found out that the phone I'm using is having version 8.3.01 (2385995-434) Google Play services which might be the root cause, are there any documentation stating that it must be higher than version 9.0.0? According to this answer stackoverflow.com/questions/43422021/…
– user1872384
Nov 30 '18 at 6:20
However in the error logs it states that I need version "12.4.51.000" instead of "8.3.01.434"
– user1872384
Nov 30 '18 at 6:46
|
show 2 more comments
You can have a look at this working code.
build.gradle(app-level)
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
}
build.gradle(project-level)
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.1.0'
}
}
Activity:
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.FirebaseTooManyRequestsException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import java.util.concurrent.TimeUnit;
public class FCMsmsTest extends AppCompatActivity {
private EditText editText;
private String mVerificationId = "";
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(FCMsmsTest.this, "onVerificationCompleted " + phoneAuthCredential.toString(), Toast.LENGTH_SHORT).show();
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(FCMsmsTest.this, "onVerificationFailed " + e.toString(), Toast.LENGTH_SHORT).show();
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(FCMsmsTest.this, "Invalid Request " + e.toString(), Toast.LENGTH_SHORT).show();
} else if (e instanceof FirebaseTooManyRequestsException) {
Toast.makeText(FCMsmsTest.this, "The SMS quota for the project has been exceeded " + e.toString(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
Toast.makeText(FCMsmsTest.this, "onCodeSent " + verificationId, Toast.LENGTH_SHORT).show();
editText.setText("");
mVerificationId = verificationId;
PhoneAuthProvider.ForceResendingToken mResendToken = token;
showDialog();
}
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fcm_sms_test);
editText = findViewById(R.id.edit_text);
findViewById(R.id.btn_send_sms).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (editText.getText().toString().trim().length() > 9) {
sendSMS("+91" + editText.getText().toString().trim());
} else {
Toast.makeText(FCMsmsTest.this, "Enter Valid PhoneNumber", Toast.LENGTH_SHORT).show();
}
}
});
}
private void sendSMS(String phoneNumber) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks);
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(FCMsmsTest.this, "signInWithCredential:success", Toast.LENGTH_SHORT).show();
FirebaseUser user = task.getResult().getUser();
} else {
Toast.makeText(FCMsmsTest.this, "signInWithCredential:failure", Toast.LENGTH_SHORT).show();
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(FCMsmsTest.this, "The verification code entered was invalid", Toast.LENGTH_SHORT).show();
}
}
}
});
}
private void showDialog() {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
final EditText edittextCode = new EditText(FCMsmsTest.this);
alert.setMessage("Enter Your Message");
alert.setTitle("Enter Your Title");
alert.setView(edittextCode);
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String YouEditTextValueString = edittextCode.getText().toString();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, YouEditTextValueString);
signInWithPhoneAuthCredential(credential);
}
});
alert.show();
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="50dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+91" />
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone" />
</TableRow>
<Button
android:id="@+id/btn_send_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Send OTP" />
</LinearLayout>
Update your project accordingly.
@user1872384 have you checked it out?
– Rumit Patel
Nov 27 '18 at 10:38
Rumit Patel, I've tried to upgrade the version but still doesn't receive an sms
– user1872384
Nov 27 '18 at 14:04
have you tried as in answer?
– Rumit Patel
Nov 27 '18 at 14:09
I've found out that the phone I'm using is having version 8.3.01 (2385995-434) Google Play services which might be the root cause, are there any documentation stating that it must be higher than version 9.0.0? According to this answer stackoverflow.com/questions/43422021/…
– user1872384
Nov 30 '18 at 6:20
However in the error logs it states that I need version "12.4.51.000" instead of "8.3.01.434"
– user1872384
Nov 30 '18 at 6:46
|
show 2 more comments
You can have a look at this working code.
build.gradle(app-level)
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
}
build.gradle(project-level)
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.1.0'
}
}
Activity:
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.FirebaseTooManyRequestsException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import java.util.concurrent.TimeUnit;
public class FCMsmsTest extends AppCompatActivity {
private EditText editText;
private String mVerificationId = "";
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(FCMsmsTest.this, "onVerificationCompleted " + phoneAuthCredential.toString(), Toast.LENGTH_SHORT).show();
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(FCMsmsTest.this, "onVerificationFailed " + e.toString(), Toast.LENGTH_SHORT).show();
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(FCMsmsTest.this, "Invalid Request " + e.toString(), Toast.LENGTH_SHORT).show();
} else if (e instanceof FirebaseTooManyRequestsException) {
Toast.makeText(FCMsmsTest.this, "The SMS quota for the project has been exceeded " + e.toString(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
Toast.makeText(FCMsmsTest.this, "onCodeSent " + verificationId, Toast.LENGTH_SHORT).show();
editText.setText("");
mVerificationId = verificationId;
PhoneAuthProvider.ForceResendingToken mResendToken = token;
showDialog();
}
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fcm_sms_test);
editText = findViewById(R.id.edit_text);
findViewById(R.id.btn_send_sms).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (editText.getText().toString().trim().length() > 9) {
sendSMS("+91" + editText.getText().toString().trim());
} else {
Toast.makeText(FCMsmsTest.this, "Enter Valid PhoneNumber", Toast.LENGTH_SHORT).show();
}
}
});
}
private void sendSMS(String phoneNumber) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks);
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(FCMsmsTest.this, "signInWithCredential:success", Toast.LENGTH_SHORT).show();
FirebaseUser user = task.getResult().getUser();
} else {
Toast.makeText(FCMsmsTest.this, "signInWithCredential:failure", Toast.LENGTH_SHORT).show();
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(FCMsmsTest.this, "The verification code entered was invalid", Toast.LENGTH_SHORT).show();
}
}
}
});
}
private void showDialog() {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
final EditText edittextCode = new EditText(FCMsmsTest.this);
alert.setMessage("Enter Your Message");
alert.setTitle("Enter Your Title");
alert.setView(edittextCode);
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String YouEditTextValueString = edittextCode.getText().toString();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, YouEditTextValueString);
signInWithPhoneAuthCredential(credential);
}
});
alert.show();
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="50dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+91" />
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone" />
</TableRow>
<Button
android:id="@+id/btn_send_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Send OTP" />
</LinearLayout>
Update your project accordingly.
You can have a look at this working code.
build.gradle(app-level)
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.0.5'
}
build.gradle(project-level)
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.1.0'
}
}
Activity:
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.FirebaseTooManyRequestsException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import java.util.concurrent.TimeUnit;
public class FCMsmsTest extends AppCompatActivity {
private EditText editText;
private String mVerificationId = "";
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(FCMsmsTest.this, "onVerificationCompleted " + phoneAuthCredential.toString(), Toast.LENGTH_SHORT).show();
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(FCMsmsTest.this, "onVerificationFailed " + e.toString(), Toast.LENGTH_SHORT).show();
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(FCMsmsTest.this, "Invalid Request " + e.toString(), Toast.LENGTH_SHORT).show();
} else if (e instanceof FirebaseTooManyRequestsException) {
Toast.makeText(FCMsmsTest.this, "The SMS quota for the project has been exceeded " + e.toString(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
Toast.makeText(FCMsmsTest.this, "onCodeSent " + verificationId, Toast.LENGTH_SHORT).show();
editText.setText("");
mVerificationId = verificationId;
PhoneAuthProvider.ForceResendingToken mResendToken = token;
showDialog();
}
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fcm_sms_test);
editText = findViewById(R.id.edit_text);
findViewById(R.id.btn_send_sms).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (editText.getText().toString().trim().length() > 9) {
sendSMS("+91" + editText.getText().toString().trim());
} else {
Toast.makeText(FCMsmsTest.this, "Enter Valid PhoneNumber", Toast.LENGTH_SHORT).show();
}
}
});
}
private void sendSMS(String phoneNumber) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks);
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(FCMsmsTest.this, "signInWithCredential:success", Toast.LENGTH_SHORT).show();
FirebaseUser user = task.getResult().getUser();
} else {
Toast.makeText(FCMsmsTest.this, "signInWithCredential:failure", Toast.LENGTH_SHORT).show();
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(FCMsmsTest.this, "The verification code entered was invalid", Toast.LENGTH_SHORT).show();
}
}
}
});
}
private void showDialog() {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
final EditText edittextCode = new EditText(FCMsmsTest.this);
alert.setMessage("Enter Your Message");
alert.setTitle("Enter Your Title");
alert.setView(edittextCode);
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String YouEditTextValueString = edittextCode.getText().toString();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, YouEditTextValueString);
signInWithPhoneAuthCredential(credential);
}
});
alert.show();
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="50dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+91" />
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone" />
</TableRow>
<Button
android:id="@+id/btn_send_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Send OTP" />
</LinearLayout>
Update your project accordingly.
answered Nov 22 '18 at 10:07
Rumit PatelRumit Patel
1,78642435
1,78642435
@user1872384 have you checked it out?
– Rumit Patel
Nov 27 '18 at 10:38
Rumit Patel, I've tried to upgrade the version but still doesn't receive an sms
– user1872384
Nov 27 '18 at 14:04
have you tried as in answer?
– Rumit Patel
Nov 27 '18 at 14:09
I've found out that the phone I'm using is having version 8.3.01 (2385995-434) Google Play services which might be the root cause, are there any documentation stating that it must be higher than version 9.0.0? According to this answer stackoverflow.com/questions/43422021/…
– user1872384
Nov 30 '18 at 6:20
However in the error logs it states that I need version "12.4.51.000" instead of "8.3.01.434"
– user1872384
Nov 30 '18 at 6:46
|
show 2 more comments
@user1872384 have you checked it out?
– Rumit Patel
Nov 27 '18 at 10:38
Rumit Patel, I've tried to upgrade the version but still doesn't receive an sms
– user1872384
Nov 27 '18 at 14:04
have you tried as in answer?
– Rumit Patel
Nov 27 '18 at 14:09
I've found out that the phone I'm using is having version 8.3.01 (2385995-434) Google Play services which might be the root cause, are there any documentation stating that it must be higher than version 9.0.0? According to this answer stackoverflow.com/questions/43422021/…
– user1872384
Nov 30 '18 at 6:20
However in the error logs it states that I need version "12.4.51.000" instead of "8.3.01.434"
– user1872384
Nov 30 '18 at 6:46
@user1872384 have you checked it out?
– Rumit Patel
Nov 27 '18 at 10:38
@user1872384 have you checked it out?
– Rumit Patel
Nov 27 '18 at 10:38
Rumit Patel, I've tried to upgrade the version but still doesn't receive an sms
– user1872384
Nov 27 '18 at 14:04
Rumit Patel, I've tried to upgrade the version but still doesn't receive an sms
– user1872384
Nov 27 '18 at 14:04
have you tried as in answer?
– Rumit Patel
Nov 27 '18 at 14:09
have you tried as in answer?
– Rumit Patel
Nov 27 '18 at 14:09
I've found out that the phone I'm using is having version 8.3.01 (2385995-434) Google Play services which might be the root cause, are there any documentation stating that it must be higher than version 9.0.0? According to this answer stackoverflow.com/questions/43422021/…
– user1872384
Nov 30 '18 at 6:20
I've found out that the phone I'm using is having version 8.3.01 (2385995-434) Google Play services which might be the root cause, are there any documentation stating that it must be higher than version 9.0.0? According to this answer stackoverflow.com/questions/43422021/…
– user1872384
Nov 30 '18 at 6:20
However in the error logs it states that I need version "12.4.51.000" instead of "8.3.01.434"
– user1872384
Nov 30 '18 at 6:46
However in the error logs it states that I need version "12.4.51.000" instead of "8.3.01.434"
– user1872384
Nov 30 '18 at 6:46
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370161%2fsms-authentication-on-android-nullpointerexception%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Reason for downvoting please
– user1872384
Nov 19 '18 at 7:49
Is it because there's no sim card on the phone? -> No. I'm using without SIM and it's working. and what variable you are getting
null?
– Rumit Patel
Nov 19 '18 at 9:26
@RumitPatel I've updated the full error code when PhoneAuthProvider.getInstance().verifyPhoneNumber is called. I'm wondering what's the root cause for the app to crash as well.
– user1872384
Nov 19 '18 at 9:49
update
com.google.gms:google-services
,com.google.firebase:firebase-core
, andcom.google.firebase:firebase-auth
to the latest and try.– Rumit Patel
Nov 19 '18 at 10:05
I'm using these: classpath 'com.google.gms:google-services:4.1.0' implementation 'com.google.firebase:firebase-database:11.6.0' implementation 'com.google.firebase:firebase-auth:11.6.0' Is it not compatible? is there a list showing which version of com.google.gms:google-services is compatible with com.google.firebase:? It's rather confusing
– user1872384
Nov 22 '18 at 9:47