[英]unable to resolve verifyPhoneNumber() in android
I am building video calling app in android using java language in which I am getting error in verifyPhoneNumber() in phone authentication in firebase.我正在使用 java 语言在 android 中构建视频通话应用程序,其中我在 firebase 的电话身份验证中遇到 verifyPhoneNumber() 错误。 Below java code,xml files and all dependencies are written.i dont know why i am getting error.I have defined all.I have googled it alot for same
下面 java 代码,xml 文件和所有依赖项都写了。我不知道为什么我收到错误。我已经定义了所有。我已经用谷歌搜索了很多相同的
MainActivity.java MainActivity.java
package com.example.dekho;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.PhoneAuthProvider;
import com.hbb20.CountryCodePicker;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeUnit;
public class MainActivity extends AppCompatActivity {
private CountryCodePicker ccp;
private EditText phoneText;
private EditText codeText;
private Button continueAndNextBtn;
private String checker="",phoneNumber="";
private RelativeLayout relativeLayout;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;
private FirebaseAuth mAuth;
private String mVerificationId;
private PhoneAuthProvider.ForceResendingToken mSendToken;
private ProgressDialog loadingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ccp=findViewById(R.id.ccp);
phoneText=findViewById(R.id.phoneText);
codeText=findViewById(R.id.codeText);
continueAndNextBtn=findViewById(R.id.continueNextButton);
relativeLayout=findViewById(R.id.phoneAuth);
continueAndNextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHORT).show();
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallbacks
}
});
}
}
xml file xml 文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/register"
tools:context=".MainActivity">
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="260dp">
</TextView>
<RelativeLayout
android:id="@+id/phoneAuth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textview1"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:padding="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Phone Number:"
android:textStyle="bold"
android:textColor="@android:color/white"
android:textSize="18sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<com.hbb20.CountryCodePicker
android:id="@+id/ccp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
app:ccp_defaultNameCode="IN" />
<EditText
android:id="@+id/phoneText"
android:layout_width="match_parent"
android:layout_height="60dp"
android:textColor="@android:color/white"
android:textColorHint="@android:color/darker_gray"
android:inputType="phone"
android:singleLine="true"
android:backgroundTint="@android:color/white"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<EditText
android:id="@+id/codeText"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="25dp"
android:hint="Write you code here..."
android:textColor="@android:color/white"
android:textColorHint="@android:color/white"
android:inputType="phone"
android:singleLine="true"
android:layout_below="@+id/phoneAuth"
android:drawableLeft="@drawable/password"
android:drawableTint="@android:color/white"
android:backgroundTint="@android:color/white"
android:visibility="gone"/>
<Button
android:id="@+id/continueNextButton"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_below="@+id/codeText"
android:layout_centerHorizontal="true"
android:text="Continue"
android:textAllCaps="false"
android:layout_marginTop="6dp"
android:textSize="15dp"
android:background="@color/colorPrimary"
android:textColor="@android:color/white"/>
</RelativeLayout>
project level dependencies项目级依赖
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app level dependencies应用级依赖
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.dekho"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.firebase:firebase-core:17.3.0'
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation 'com.google.firebase:firebase-storage:19.1.1'
//implementation 'com.google.firebase:firebase-ui-database:3.2.2'
implementation 'com.google.firebase:firebase-auth:19.3.0'
implementation 'com.hbb20:ccp:2.1.9'
implementation 'pub.devrel:easypermissions:0.4.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-core:11.4.0'
implementation 'com.google.firebase:firebase-messaging:11.4.0'
implementation 'com.google.firebase:firebase-auth:11.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Error log错误日志
2020-04-16 12:39:03.571 26139-26139/? I/m.example.dekh: Late-enabling -Xcheck:jni
2020-04-16 12:39:03.638 26139-26139/? W/re-initialized>: type=1400 audit(0.0:82712): avc: denied { read } for name="u:object_r:mtk_amslog_prop:s0" dev="tmpfs" ino=12437 scontext=u:r:untrusted_app:s0:c252,c256,c512,c768 tcontext=u:object_r:mtk_amslog_prop:s0 tclass=file permissive=0
2020-04-16 12:39:03.642 26139-26139/? E/libc: Access denied finding property "persist.vendor.sys.activitylog"
2020-04-16 12:39:03.717 26139-26139/com.example.dekho D/VivoTheme: load old package name start
2020-04-16 12:39:04.220 26139-26139/com.example.dekho W/FirebaseApp: Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
2020-04-16 12:39:04.220 26139-26139/com.example.dekho I/FirebaseInitProvider: FirebaseApp initialization unsuccessful
2020-04-16 12:39:04.236 26139-26139/com.example.dekho D/NightModeController: com.example.dekho = true
2020-04-16 12:39:04.236 26139-26139/com.example.dekho D/NightModeController: disable nightmode package:com.example.dekho
2020-04-16 12:39:04.322 26139-26139/com.example.dekho I/FtBuild: getRomVersion mRomVer=9.0
2020-04-16 12:39:04.337 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking)
2020-04-16 12:39:04.338 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking)
2020-04-16 12:39:04.338 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking)
2020-04-16 12:39:04.338 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking)
2020-04-16 12:39:04.338 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking)
2020-04-16 12:39:04.381 26139-26139/com.example.dekho D/VivoPhoneWindow: DEBUG_ALIENSCREEN:getRotation mRotation=0
2020-04-16 12:39:04.381 26139-26139/com.example.dekho I/PhoneWindow: initSystemUIColor
2020-04-16 12:39:04.441 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2020-04-16 12:39:04.444 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2020-04-16 12:39:04.497 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden method Landroid/widget/TextView;->getTextDirectionHeuristic()Landroid/text/TextDirectionHeuristic; (light greylist, linking)
2020-04-16 12:39:04.513 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden method Landroid/graphics/FontFamily;-><init>()V (light greylist, reflection)
2020-04-16 12:39:04.513 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontVariationAxis;)Z (light greylist, reflection)
2020-04-16 12:39:04.513 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontVariationAxis;II)Z (light greylist, reflection)
2020-04-16 12:39:04.513 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden method Landroid/graphics/FontFamily;->freeze()Z (light greylist, reflection)
2020-04-16 12:39:04.513 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden method Landroid/graphics/FontFamily;->abortCreation()V (light greylist, reflection)
2020-04-16 12:39:04.514 26139-26139/com.example.dekho W/m.example.dekh: Accessing hidden method Landroid/graphics/Typeface;->createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (light greylist, reflection)
2020-04-16 12:39:04.534 26139-26139/com.example.dekho D/CCP: init:xmlWidth -2
2020-04-16 12:39:04.560 26139-26139/com.example.dekho D/CCP: updateLanguageToApply: ENGLISH
2020-04-16 12:39:04.763 26139-26139/com.example.dekho D/CCP: updateFormattingTextWatcher: EditText not registered CCP_last_selection
2020-04-16 12:39:04.766 26139-26139/com.example.dekho D/CCP: end:xmlWidth -2
2020-04-16 12:39:04.864 26139-26139/com.example.dekho D/OpenGLRenderer: Dumper init 4 threads <0x6fcfbd2d40>
2020-04-16 12:39:04.864 26139-26139/com.example.dekho D/OpenGLRenderer: <com.example.dekho> is running.
2020-04-16 12:39:04.864 26139-26139/com.example.dekho D/OpenGLRenderer: Skia GL Pipeline
2020-04-16 12:39:04.865 26139-26139/com.example.dekho I/SurfaceFactory: [static] sSurfaceFactory = com.mediatek.view.impl.SurfaceFactoryImpl@a0e3075
2020-04-16 12:39:04.885 26139-26139/com.example.dekho D/ViewRootImpl[MainActivity]: hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false
2020-04-16 12:39:04.904 26139-26139/com.example.dekho V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@7c35698, this = DecorView@41e5ef1[MainActivity]
2020-04-16 12:39:04.919 26139-26139/com.example.dekho I/TouchMotionHandler: handler onAttached
2020-04-16 12:39:05.019 26139-26139/com.example.dekho D/Surface: Surface::allocateBuffers(this=0x6fd7cfb000)
2020-04-16 12:39:05.027 26139-26169/com.example.dekho I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2020-04-16 12:39:05.028 26139-26169/com.example.dekho I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2020-04-16 12:39:05.028 26139-26169/com.example.dekho I/OpenGLRenderer: Initialized EGL, version 1.4
2020-04-16 12:39:05.028 26139-26169/com.example.dekho D/OpenGLRenderer: Swap behavior 2
2020-04-16 12:39:05.044 26139-26169/com.example.dekho D/Surface: Surface::connect(this=0x6fd7cfb000,api=1)
2020-04-16 12:39:05.127 26139-26169/com.example.dekho E/ion: ioctl c0044901 failed with code -1: Invalid argument
2020-04-16 12:39:06.690 26139-26139/com.example.dekho D/TextView: touchFinish handled:false --- mShowToolbar=false
2020-04-16 12:39:06.712 26139-26139/com.example.dekho I/AssistStructure: Flattened final assist data: 4084 bytes, containing 1 windows, 15 views
2020-04-16 12:39:07.075 26139-26139/com.example.dekho D/AndroidRuntime: Shutting down VM
2020-04-16 12:39:07.079 26139-26139/com.example.dekho E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dekho, PID: 26139
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.dekho. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@19.3.0:184)
at com.google.firebase.auth.PhoneAuthProvider.getInstance(com.google.firebase:firebase-auth@@19.3.0:5)
at com.example.dekho.MainActivity$1.onClick(MainActivity.java:51)
at android.view.View.performClick(View.java:6647)
at android.view.View.performClickInternal(View.java:6620)
at android.view.View.access$3100(View.java:791)
at android.view.View$PerformClick.run(View.java:26346)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7081)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:536)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:928)
2020-04-16 12:39:07.103 26139-26139/com.example.dekho I/Process: Sending signal. PID: 26139 SIG: 9
You are passing the wrong set of arguments to verifyPhoneNumber()
.您将错误的 arguments 集传递给
verifyPhoneNumber()
。 The this
keyword inside OnClickListener
is the problem. OnClickListener
中的this
关键字是问题所在。 Calling this
inside setOnClickListener()
refered to the OnClickListener
your passing and not the activity.在
setOnClickListener()
内部调用this
指的是OnClickListener
您的传递,而不是活动。 So, there you have to use like MainActivity.this
for it to refer to the activity.因此,您必须使用
MainActivity.this
来引用活动。
Kindly update the OnClickListener
as follows请按如下方式更新
OnClickListener
continueAndNextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
MainActivity.this, // Uses the <ActivityName>.this instead of just "this" Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallbacks
}
});
Update更新
With regarding OP's crash issue: It says right in the attached stack trace that关于 OP 的崩溃问题:它在附加的堆栈跟踪中说
Make sure to call FirebaseApp.initializeApp(Context)
first.确保首先调用
FirebaseApp.initializeApp(Context)
。
So you need to initialize FirebaseApp in the onCreate()
method of either因此,您需要在任一的
onCreate()
方法中初始化 FirebaseApp
by calling通过调用
FirebaseApp.initializeApp(this);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.