android - update - Autenticación con Firebase antiguo y nuevo
update firebase user android (0)
Tengo un problema que no puedo conectar con más de un proveedor de Internet con mi aplicación. Primero creí que era la nueva versión de Firebase, pero parece ser otra cosa.
Si instalo un nuevo emulador dentro de Android Studio y me conecto a cualquier conexión de internet, solo me permitirá usar esa conexión para ingresar a mi aplicación.
Cuando creo un nuevo proyecto y lo pruebo, el problema sigue ahí.
siguiendo dentro loginActivity no se llama.
firebaseRef.authWithPassword()
Me da el siguiente diálogo
La actividad o las credenciales de autenticación pendientes fueron suprimidas por otra llamada a auth
Y esto salió ahora
Hubo una excepción al conectar con el servidor de autenticación: no se puede resolver hos "auth.firebase.com": ninguna dirección asociada con el nombre de host
SDK Tools - Servicio Google Play (versión 30)
Herramientas de SDK - Repositorio de Google (versión 26)
Android Studio 2.1.1
Servicio Google Play 9.0.80 en emulador
Acceda a un usuario : Correo electrónico: [email protected] Contraseña: 12345678
Actividad de acceso
public class LoginActivity extends AppCompatActivity {
protected EditText emailEditText;
protected EditText passwordEditText;
protected Button loginButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// example: https://todoapprj.firebaseio.com/users/0736e525-fe72-44f7-a828-c4d1c66d541c
// Getting the firebase reference url
final Firebase ref = new Firebase("https://todoapprj.firebaseio.com");
//setting up the Views
emailEditText = (EditText) findViewById(R.id.emailField);
passwordEditText = (EditText) findViewById(R.id.passwordField);
loginButton = (Button) findViewById(R.id.loginButton);
// LOGIN BUTTON
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("Pressed", "login button");
// Reterives user inputs
String email = emailEditText.getText().toString();
String password = passwordEditText.getText().toString();
// trims the input
email = email.trim();
password = password.trim();
// Authentaction Check for login.
if (email.isEmpty() || password.isEmpty()) {
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setMessage(R.string.login_error_message)
.setTitle(R.string.login_error_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
} else {
final String emailAddress = email;
Log.i("Before", "authWithPassword");
//Login with email/password combination
ref.authWithPassword(email, password, new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
Log.i("Inside", "authWithPassword");
// Authenticated successfully with authData
Map<String, Object> map = new HashMap<String, Object>();
map.put("email", emailAddress);
ref.child("users").child(authData.getUid()).updateChildren(map); // VIKTIGT ATT ÄR UPDATECHILDREN ANNARS FÖRSVINNER DET VID UTLOGGNING
Intent intent = new Intent(LoginActivity.this, MainRealb.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
// If authenticated failed with error
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
Log.i("Auth", "error");
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setMessage(firebaseError.getMessage())
.setTitle(R.string.login_error_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
});
}
}
});
}
Actividad principal
public class MainRealb extends AppCompatActivity {
Firebase mainRef = null;
private String waypointsUrl;
private String mUserId;
private Firebase mRef;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainreal);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Används för att fungera offline - setPersistenceEnabled(true)
Firebase.setAndroidContext(this);
mRef = new Firebase("https://todoapprj.firebaseio.com");
if (mRef.getAuth() == null) {
loadLoginView();
}
try {
mUserId = mRef.getAuth().getUid();
} catch (Exception e) {
loadLoginView();
}
waypointsUrl = "https://todoapprj.firebaseio.com" + "/users/" + mUserId + "/waypoints";
mainRef = new Firebase(waypointsUrl);
Log.i("test", mainRef + "" + mUserId);
}
private void loadLoginView() {
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_logout) {
mRef.unauth();
loadLoginView();
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
Gradle
apply plugin: ''com.android.application''
android {
compileSdkVersion 23
buildToolsVersion ''23.0.3''
// This excludes those files from the build to avoid potential build errors due to duplicate files.
packagingOptions {
exclude ''META-INF/LICENSE''
exclude ''META-INF/LICENSE-FIREBASE.txt''
exclude ''META-INF/NOTICE''
}
defaultConfig {
applicationId "com.example.rasmusjosefsson.rjcar"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(''proguard-android.txt''), ''proguard-rules.pro''
}
}
}
dependencies {
compile fileTree(dir: ''libs'', include: [''*.jar''])
testCompile ''junit:junit:4.12''
compile ''com.android.support:appcompat-v7:23.3.0''
compile ''com.android.support:design:23.3.0''
compile ''com.android.support:support-v4:23.3.0''
compile ''com.android.support:recyclerview-v7:23.3.0''
compile ''com.android.support:cardview-v7:23.3.0''
compile ''com.squareup.retrofit2:retrofit:2.0.2''
compile ''com.squareup.retrofit2:converter-gson:2.0.1''
compile ''com.squareup.okhttp3:okhttp:3.2.0''
compile ''com.google.code.gson:gson:2.6.2''
compile ''com.google.maps.android:android-maps-utils:0.4.3''
compile ''com.google.maps:google-maps-services:0.1.12''
compile ''com.google.android.gms:play-services-ads:8.4.0''
compile ''com.google.android.gms:play-services-auth:8.4.0''
compile ''com.google.android.gms:play-services-gcm:8.4.0''
compile ''com.google.android.gms:play-services-location:8.4.0''
compile ''com.firebase:firebase-client-android:2.5.2''
compile ''com.firebaseui:firebase-ui:0.3.1''
}