我的问题是我不知道为什么我的创建帐户代码无法正常工作,我让我的“创建帐户”
package rs.studenty.studentylanguage;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
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.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.UserProfileChangeRequest;
public class MainActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private EditText email,password,name;
private Button sign_in, sign_up;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance(); // important call
sign_in = (Button)findViewById(R.id.button_sign_in_01);
sign_up = (Button)findViewById(R.id.button_sign_up_01);
name = (EditText)findViewById(R.id.etName);
email = (EditText)findViewById(R.id.etEmail);
password = (EditText)findViewById(R.id.etPassword);
//Check if user is already Logged In
if(mAuth.getCurrentUser() !=null)
{
//User Not Logged In
finish();
startActivity(new Intent(getApplicationContext(),SignIn.class));
}
sign_in.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String getemail = email.getText().toString().trim();
String getpassword = password.getText().toString().trim();
callsing_in(getemail, getpassword);
}
});
sign_up.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String getemail = email.getText().toString().trim();
String getpassword = password.getText().toString().trim();
callesign_up(getemail,getpassword);
}
});
}
//Create Account
private void callesign_up(String email,String password) {
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d("TESTING", "Sign up sucessfull" + task.isSuccessful());
//If sign in falls, display a message to the user. It sign in succeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Signed up failed", Toast.LENGTH_SHORT).show();
} else
{
userProfile();
Toast.makeText(MainActivity.this, "Created Account", Toast.LENGTH_SHORT).show();
Log.d("TESTING", "Created Account");
}
}
});
}
//Set User Display Account
private void userProfile()
{
FirebaseUser user = mAuth.getCurrentUser();
if(user!= null)
{
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder().setDisplayName(name.getText().toString().trim())
//.setPhotoUri(Uri.parse("https://Example.com/jane-q-user/profile.jpg")) //here you can set image link also.
.build();
user.updateProfile(profileUpdates)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d("TESTING", "User profile updated");
}
}
});
}
//Now Start Sign In Process
//SignIn Process
private void callsing_in(String email, String password) {
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d("TESTING", "Sign In Succesful:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if(!task.isSuccessful()) {
Log.v("TESTING", "singInWithEmail:Failed", task.getException());
Toast.makeText(MainActivity.this, "Failed", Toast.LENGTH_SHORT).show();
}
else {
Intent i = new Intent(MainActivity.this, SignIn.class);
finish();
startActivity(i);
}
}
});
}
}
我想在这里放置LOGCAT错误网站:
5-15 21:11:28.054 27023-27023/? E/appproc: Enhanced Zygote ASLR:
ro.knox.enhance.zygote.aslr != 1. Enhanced Zygote ASLR is DISABLED!
05-15 21:11:28.241 27023-27023/? E/SemAffinityControl: SemAffinityControl:
registerfunction enter
05-15 21:11:28.986 3161-4129/? E/Watchdog: !@Sync 15106 [2018-05-15
21:11:28.986]
05-15 21:11:29.265 27042-27042/? E/appproc: Enhanced Zygote ASLR:
ro.knox.enhance.zygote.aslr != 1. Enhanced Zygote ASLR is DISABLED!
05-15 21:11:29.449 27042-27042/? E/SemAffinityControl: SemAffinityControl:
registerfunction enter
05-15 21:11:32.236 27056-27056/? E/appproc: Enhanced Zygote ASLR:
ro.knox.enhance.zygote.aslr != 1. Enhanced Zygote ASLR is DISABLED!
05-15 21:11:32.243 27058-27058/? E/appproc: Enhanced Zygote ASLR:
ro.knox.enhance.zygote.aslr != 1. Enhanced Zygote ASLR is DISABLED!
05-15 21:11:32.423 27056-27056/? E/SemAffinityControl: SemAffinityControl:
registerfunction enter
05-15 21:11:32.430 27058-27058/? E/SemAffinityControl: SemAffinityControl:
registerfunction enter
05-15 21:11:33.187 27081-27081/? E/appproc: Enhanced Zygote ASLR:
ro.knox.enhance.zygote.aslr != 1. Enhanced Zygote ASLR is DISABLED!
05-15 21:11:33.365 27081-27081/? E/SemAffinityControl: SemAffinityControl:
registerfunction enter
05-15 21:11:33.456 27093-27093/? E/Zygote: v2
05-15 21:11:33.457 27093-27093/? E/Zygote: accessInfo : 0
05-15 21:11:33.485 27093-27100/? E/art: Failed sending reply to debugger:
Broken pipe
05-15 21:11:35.487 27093-27093/rs.studenty.studentylanguage
E/BoostFramework: BoostFramework() : Exception_1 =
java.lang.ClassNotFoundException: Didn't find class
"com.qualcomm.qti.Performance" on path:
DexPathList[[],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]]
05-15 21:11:35.666 5017-5017/? E/SKBD: za setCurrentInputModule
mCurrentInputModule index: 19
05-15 21:11:35.684 5017-5017/? E/SKBD: za setCurrentInputModule
mCurrentInputModule index: 19
05-15 21:11:35.704 5017-5017/? E/SKBD: get previous
05-15 21:11:37.736 5017-5017/? E/KeyboardInfoUtils: getInstance start
sendSIPInformation state:6 isAbstractKeyboardView : true
05-15 21:11:37.737 5017-27166/? E/KeyboardInfoUtils: sending null
keyboardInfo as SIP is closed
05-15 21:11:37.807 5017-5017/? E/SKBD: za setCurrentInputModule
mCurrentInputModule index: 19
05-15 21:11:37.828 5017-5017/? E/SKBD: za setCurrentInputModule
mCurrentInputModule index: 19
05-15 21:11:40.891 5017-5017/? E/KeyboardInfoUtils: getInstance start
sendSIPInformation state:6 isAbstractKeyboardView : true
05-15 21:11:40.892 5017-27191/? E/KeyboardInfoUtils: sending null
keyboardInfo as SIP is closed
05-15 21:11:40.963 5017-5017/? E/SKBD: za setCurrentInputModule
mCurrentInputModule index: 19
05-15 21:11:40.982 5017-5017/? E/SKBD: za setCurrentInputModule
mCurrentInputModule index: 19
05-15 21:11:44.094 3161-13609/? E/InputMethodManagerService: Perflock object
null
05-15 21:11:44.097 5017-5017/? E/KeyboardInfoUtils: getInstance start
sendSIPInformation state:6 isAbstractKeyboardView : true
05-15 21:11:44.098 5017-27218/? E/KeyboardInfoUtils: sending null
keyboardInfo as SIP is closed
05-15 21:11:44.146 5017-5017/? E/SKBD: processWhenPickSuggestionManually :
32
05-15 21:11:45.073 11025-18394/? E/Volley: [74438]
BasicNetwork.performRequest: Unexpected response code 403 for
https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?
alt=proto&key=AIzaSyB5sv1PmXW5F0zytedxMuuCNmaaGggfFqg
05-15 21:11:45.130 11025-18394/? E/Volley: [74438]
BasicNetwork.performRequest: Unexpected response code 403
for
https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?
alt=proto&key=AIzaSyB5sv1PmXW5F0zytedxMuuCNmaaGggfFqg
这里我们有android清单源代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="rs.studenty.studentylanguage">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SignIn" />
</application>
如果有人可以帮我,那真是太棒了,因为我很新。我正在努力解决这个问题,但我不能那么高兴......
感谢所有试图解决此问题的方法:)