- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道我可以在 stackoverflow 上看到很多关于这个主题的问题,我已经尝试了几乎所有的问题,但还没有成功,所以这是我发布新问题的唯一选择。
我的问题是 FirebaseAuth.getInstance 总是返回 null,即使我已经初始化了 FirebaseApp。我的主要目的是使用来自 firebase 的手机身份验证,我已在 firebase 控制台中启用它。
我做过的事情-
应用级 Gradle
//apply plugin: 'kotlin-android'
apply plugin: 'com.android.application'
apply plugin: 'androidx.navigation.safeargs'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.ajoobee.mm"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.0.0-rc02'
implementation 'androidx.navigation:navigation-ui:2.0.0-rc02'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
//add kotlin
/* implementation "androidx.core:core-ktx:1.0.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"*/
implementation "com.github.leonardoxh:retrofit2-livedata-adapter:1.1.2"
//Internet Checker
implementation 'com.treebo:internetavailabilitychecker:1.0.2'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.okhttp3:okhttp:3.11.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
//Android Jetpack
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.1.0'
// implementation "android.arch.lifecycle:extensions:1.1.1"
//ButterKnife
implementation 'com.jakewharton:butterknife:10.2.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
//Dagger implementation 'com.google.dagger:dagger-android:2.17'
implementation 'com.google.dagger:dagger-android-support:2.17'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.17'
/* Dagger2 - default dependency */
annotationProcessor 'com.google.dagger:dagger-compiler:2.17'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
//circle image view
implementation 'de.hdodenhof:circleimageview:3.0.1'
//room database
implementation 'androidx.room:room-runtime:2.1.0'
annotationProcessor 'androidx.room:room-compiler:2.1.0'
implementation 'com.jakewharton.timber:timber:4.7.1'
//ImagePicker and Glide
implementation group: 'com.zhihu.android', name: 'matisse', version: '0.5.2'
implementation 'com.github.bumptech.glide:glide:4.9.0'
//SummerNote
implementation 'in.nashapp.androidsummernote:androidsummernote:1.0.5'
//uCrop
implementation 'com.github.yalantis:ucrop:2.2.4-native'
//roundedImageView
implementation 'com.makeramen:roundedimageview:2.3.0'
//progressBarChart
implementation 'com.ramijemli.percentagechartview:percentagechartview:0.3.1'
//googleLocation
implementation "com.google.android.gms:play-services-location:17.0.0"
implementation 'com.google.android.libraries.places:places:2.0.0'
//implementation project(':multiselectspinner')
implementation 'com.droidninja:filepicker:2.2.1'
//firebase
implementation 'com.google.firebase:firebase-auth:19.1.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
}
apply plugin: 'com.google.gms.google-services'
我的项目级Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
//ext.kotlin_version = '1.3.30'
repositories {
google()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.30"
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0'
classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0'
classpath 'com.google.gms:google-services:4.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的 fragment
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.navigation.NavOptions;
import androidx.navigation.Navigation;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.ajoobee.mm.Constants;
import com.ajoobee.mm.Data.Network.Response.ServerResult;
import com.ajoobee.mm.Data.Network.Retrofit.AuthenticationInterceptor;
import com.ajoobee.mm.Employer.UI.Home.Profile.PopUpWindow.CityPopUpWindow;
import com.ajoobee.mm.Employer.UI.Home.Profile.UpdateCompanyViewModel;
import com.ajoobee.mm.JobSeeker.UI.Home.Profile.JobSeekerProfileViewModel;
import com.ajoobee.mm.R;
import com.ajoobee.mm.Util.ErrorDialog;
import com.ajoobee.mm.Util.Util;
import com.ajoobee.mm.ViewModelFactory;
import com.ajoobee.mm.databinding.JobseekerFragmentRegisterBinding;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseException;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import com.google.gson.JsonObject;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import dagger.android.support.AndroidSupportInjection;
public class JobSeekerRegisterFragment extends Fragment {
private JobseekerFragmentRegisterBinding binding;
private JobSeekerProfileViewModel jobSeekerProfileViewModel;
private UpdateCompanyViewModel updateCompanyViewModel;
private CityPopUpWindow cityPopUpWindow;
private int city;
private boolean first = true;
private ErrorDialog errorDialog;
@Inject
ViewModelFactory viewModelFactory;
@Inject
AuthenticationInterceptor authenticationInterceptor;
private FirebaseAuth mAuth;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.jobseeker_fragment_register, container, false);
init();
if(this.getContext() != null){
FirebaseApp.initializeApp(this.getContext());
mAuth = FirebaseAuth.getInstance();
}
return binding.getRoot();
}
@Override
public void onStart() {
super.onStart();
FirebaseUser firebaseUser = mAuth.getCurrentUser();
if(firebaseUser != null){
Toast.makeText(this.getContext(), "Already Sign in ", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this.getContext(), "mAuth Still null ", Toast.LENGTH_SHORT).show();
}
}
private void init() {
if (this.getActivity() != null) {
if (this.getActivity().getIntent() != null) {
Intent intent = this.getActivity().getIntent();
if (intent.getBooleanExtra(Constants.LOGIN, false)) {
NavOptions navOptions = new NavOptions.Builder()
.setPopUpTo(R.id.jobSeekerEmailVeriRequiredFragment, true)
.build();
Navigation.findNavController(JobSeekerRegisterFragment.this.getActivity(), R.id.fragment).navigate(R.id.jobSeekerEmailVeriRequiredFragment, new Bundle(), navOptions);
}
}
}
if (this.getContext() != null) {
errorDialog = new ErrorDialog(this.getContext(), new ErrorDialog.OkButtonClick() {
@Override
public void onOkClick() {
}
});
binding.txtCity.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
if (first) {
cityPopUpWindow = new CityPopUpWindow(this.getContext(), binding.txtCity, city, id -> {
city = id;
cityPopUpWindow.dismiss();
cityPopUpWindow.opened = false;
binding.dropDownImageView.animate().rotation(0).start();
});
first = false;
}
});
jobSeekerProfileViewModel = ViewModelProviders.of(this, viewModelFactory).get(JobSeekerProfileViewModel.class);
updateCompanyViewModel = ViewModelProviders.of(this, viewModelFactory).get(UpdateCompanyViewModel.class);
//ClickableSpan
SpannableString spannableString = new SpannableString(getString(R.string.jobseeker_signup_already_account));
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
Intent intent = new Intent(getActivity(), JobSeekerLogin.class);
JobSeekerRegisterFragment.this.startActivity(intent);
}
};
spannableString.setSpan(clickableSpan, 25, 30, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.activeControlColor)), 25, 30, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableString.setSpan(new UnderlineSpan(), 0, spannableString.length(), 0);
binding.alreadyHaveAccountTextView.setText(spannableString);
binding.alreadyHaveAccountTextView.setMovementMethod(LinkMovementMethod.getInstance());
binding.alreadyHaveAccountTextView.setHighlightColor(Color.TRANSPARENT);
//ClickableSpan
//ClickListener
binding.txtCity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cityPopUpWindow.show();
if (cityPopUpWindow.opened) {
binding.dropDownImageView.animate().rotation(180).start();
} else {
binding.dropDownImageView.animate().rotation(0).start();
}
}
});
binding.btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// if (CheckCondition()) {
// sendToRegister();
// }
getVerificationCode();
}
});
//ClickListener
//City
updateCompanyViewModel.Api_City();
updateCompanyViewModel.observeCity().observe(this, listServerResult -> {
if (listServerResult != null) {
if (listServerResult.getResponse().getCode().equals("200")) {
if (cityPopUpWindow != null) {
if (cityPopUpWindow.cityPopUpAdapter != null) {
cityPopUpWindow.cityPopUpAdapter.addCity(listServerResult.getResult());
cityPopUpWindow.cityPopUpAdapter.notifyDataSetChanged();
}
}
}
}
});
//City
//Registration
jobSeekerProfileViewModel.observeRegistration().observe(this, new Observer<ServerResult<JsonObject>>() {
@Override
public void onChanged(ServerResult<JsonObject> jsonObjectServerResult) {
if (jsonObjectServerResult != null) {
if (jsonObjectServerResult.getResponse().getCode().equals("200")) {
if (jsonObjectServerResult.getResult() != null) {
if (jsonObjectServerResult.getResult().size() > 0) {
JsonObject jsonObject = jsonObjectServerResult.getResult().get(0);
if (JobSeekerRegisterFragment.this.getActivity() != null) {
authenticationInterceptor.tokenId = jsonObject.get("token").getAsString();
Navigation.findNavController(JobSeekerRegisterFragment.this.getActivity(), R.id.fragment).navigate(R.id.action_jobSeekerRegisterFragment_to_jobSeekerEmailVerificationFragment);
}
}
}
} else {
errorDialog.updateTitleAndShow(jsonObjectServerResult.getResponse().getMessage());
}
}
}
});
//Registration
}
}
private boolean CheckCondition() {
if (this.getContext() != null) {
if (Util.checkConnection(this.getContext())) {
if (binding.txtContactInfoEmail.getText().toString().isEmpty()) {
errorDialog.updateTitleAndShow(getString(R.string.signup_error_missing_email_or_phone));
return false;
} else {
if (!Util.checkEmail(binding.txtContactInfoEmail.getText().toString())) {
if (!Util.checkPhoneNumber(binding.txtContactInfoEmail.getText().toString())) {
errorDialog.updateTitleAndShow(getString(R.string.signup_error_missing_email_phone_valid));
return false;
}
}
}
if (binding.txtFullName.getText().toString().isEmpty()) {
errorDialog.updateTitleAndShow(getString(R.string.signup_error_missing_full_name));
return false;
}
if (binding.txtPasword.getText().toString().isEmpty()) {
errorDialog.updateTitleAndShow(getString(R.string.signup_error_missing_password));
return false;
} else {
if (binding.txtPasword.getText().toString().length() < 6 || !Util.checkPassword(binding.txtPasword.getText().toString())) {
errorDialog.updateTitleAndShow(getString(R.string.signup_error_password_character));
return false;
}
}
if (binding.txtConfirmPassword.getText().toString().isEmpty()) {
errorDialog.updateTitleAndShow(getString(R.string.signup_error_confirm_password));
return false;
}
if (binding.txtCity.getText().toString().isEmpty()) {
errorDialog.updateTitleAndShow(getString(R.string.signup_error_missing_location));
return false;
}
if (!binding.txtPasword.getText().toString().equals(binding.txtConfirmPassword.getText().toString())) {
errorDialog.updateTitleAndShow(getString(R.string.signup_error_missing_password_match));
return false;
}
return true;
} else {
errorDialog.updateTitleAndShow(getResources().getString(R.string.no_internet_connection));
return false;
}
} else {
return false;
}
}
private void getVerificationCode() {
if(mAuth != null){
PhoneAuthProvider.getInstance(mAuth).verifyPhoneNumber(
"09798423585", // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this.getActivity(), // Activity (for callback binding)
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(getContext(), "Verification Completed", Toast.LENGTH_SHORT).show();
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
Toast.makeText(getContext(), "Verification failed", Toast.LENGTH_SHORT).show();
}
});
}
}
private void sendToRegister() {
com.ajoobee.mm.Data.Obj.JobSeeker.JobSeekerRegister jobSeekerRegister = new com.ajoobee.mm.Data.Obj.JobSeeker.JobSeekerRegister(
binding.txtFullName.getText().toString(),
binding.txtPasword.getText().toString(),
binding.txtContactInfoEmail.getText().toString(),
"",
"",
"",
"1",
""
);
if (this.getActivity() != null) {
((JobSeekerRegisterActivity) this.getActivity()).email = binding.txtContactInfoEmail.getText().toString();
}
jobSeekerProfileViewModel.Api_JobSeekerRegistration(jobSeekerRegister);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
AndroidSupportInjection.inject(this);
}
}
错误信息
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.auth.FirebaseUser com.google.firebase.auth.FirebaseAuth.getCurrentUser()' on a null object reference
你可以看到我试图让当前用户 onStart 功能,但它曾经失败过。我调试了每一行,mAuth 始终为空。
最佳答案
终于找到答案了,原来是因为
tools:node="replace"
在 list 中。只需将其删除即可正常工作。
关于android - FirebaseAuth.getInstance() 总是返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58496920/
我正在按照本教程创建 Singleton,所有者在以下方法时有评论 http://www.journaldev.com/1377/java-singleton-design-pattern-best-
package com.example.vivanksharma.firebase; import android.support.v7.app.AppCompatActivity; import a
自从首次引入它来替换 Date 以来,我一直在使用静态方法 Calendar.getInstance() 来获取新的 Calendar目的。我从来没有遇到过问题,但出于某种原因我只是想知道使用 Gre
我正在使用适用于 Windows 8 的 MVVM Light 第 4 版;它包括 SimpleIOC。在各种示例中,我有时会看到基于 SimpleIoc 请求对象的代码......有时它基于 Ser
我看过这个post关于注册泛型类型。 如何注册的示例: bind(new TypeLiteral>() {}).to((Class>) ResponseDal.class); 但是如何从注入(inj
我想在我的 unitTest 中从 Guice injector 注入(inject)一个实例。 我可以使用哪个微分器? 我知道构造函数参数中使用了@annotation机制 但是 junit 不允许
我正在使用静态实例对象来获取与应用程序中另一个 Activity 相关的数据。但这会导致内存泄漏。 public class ChartActivity extends AppCompatActivi
以前用过C#,我考虑过 Calendar cal = Calendar.getInstance(); 根据 GoF 成为单例方法 Singleton pattern (Wikipedia)我想知道如何
我很难找到以对性能最友好的方式使用单例类的正确方法。我有 3 种方法,也许有人可以向我解释最有效的方法: 1: public functionA() { SingletonClassA.get
最近我阅读了一些使用广泛遵循 getInstance() 方法的 C++ 代码: class S { private: int some_int = 0; public
许多公开可用的 Java API 似乎都使用 getInstance 来生成和返回对象。我很好奇为什么会这样——为什么不直接使用默认/参数化构造函数呢? 是否有关联的设计模式? 最佳答案 我建议阅读
我遇到过单例模式。我无法理解 singletonobj.getinstance().dosomething() //1st one 和 singletonobj.dosomething() //2nd
getInstance() 在 Java 中的作用是什么? 在我的研究过程中,我一直在读到 getInstance() 有助于实现单例设计模式(据我了解,这意味着整个程序中只有一个实例)。但是我不能只
Firebase Firestore 提供 getInstance()方法,它打开一个套接字(在应用程序执行的任何时候只有一个)并实例化 Firestore 客户端。 我想查询和存储数据,使用或不使用
我正在将一个表单组件放入 joomla.In 中,我将在其中放置一个文本框、一个编辑器和一个按钮。 我为此表单创建了 View 文件,并且组件已成功安装。但是当我单击以在前端显示此表单时,会出现如下错
我正在尝试跟踪人们是否从广告或其他地方找到了我的 Android 应用。所以我发现谷歌分析可以通过这个表单生成的精心构建的 url 来跟踪它: http://code.google.com/mobil
我观看了此视频(https://www.youtube.com/watch?v=idb6hOxlyb8),该视频是2013年8月上传的。它声称我们应该使用 ptor.get(url) 而不是 brow
创建 google-service.json 后运行示例时,应用在尝试在 SignInActivity 中获取数据库引用时崩溃 mDatabase = FirebaseDatabase.getInst
基于以下问题:Decimal point or decimal comma in Android我尝试获取设备中使用的小数点分隔符。我正在使用Kotlin,因此我的代码如下所示: import and
从 Fabric Crashlytics 迁移到 FirebaseCrashlytics SDK 后,我在另一个进程(不是主进程)上遇到了一些崩溃。 当在 Activity 中调用 FirebaseC
我是一名优秀的程序员,十分优秀!