Android Studio Firebase Kullanımı ve Nasıl Ekleni, Android Studio Firebase database kullanımı, Firebase Kullanımı, Firebase database oluşturma, Firebase nedir, Firebase Add, Https firebase google com docs android setup available librariesi Firebase download, Firebase backend

build.gradle Module:app Eklenecek Kütüphaneler

implementation 'com.google.firebase:firebase-auth:16.2.1'
implementation 'com.firebaseui:firebase-ui-auth:4.3.2'
implementation 'com.google.firebase:firebase-database:16.1.0'

AndroidManifest.xml Dosyasına Eklenmesi Gereken İzin

Android Studio Firebase Kullanımı

Diğer Firebase Realtime Database İşlemleri İçin

<uses-permission android:name="android.permission.INTERNET"/>

MainActivity.java

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.IdpResponse;
import java.util.Arrays;
import java.util.List;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class MainActivity extends AppCompatActivity {
    private static final int MY_REQUEST_CODE = 7117; // Any number you want
    List<AuthUI.IdpConfig> providers;
    Button btn_sign_out;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn_sign_out=(Button)findViewById(R.id.btn_sgn_out);
        btn_sign_out.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Logout
                AuthUI.getInstance()
                        .signOut(MainActivity.this)
                        .addOnCompleteListener(new OnCompleteListener<Void>() {
                            @Override
                            public void onComplete(@NonNull Task<Void> task) {
                                btn_sign_out.setEnabled(false);
                                showSignInOptions();

                            }
                        }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Toast.makeText(MainActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();

                    }
                });
            }
        });

        //Init provider
        providers= Arrays.asList(
                new AuthUI.IdpConfig.EmailBuilder().build()
        );
       showSignInOptions();

    }

    private void showSignInOptions() {
        startActivityForResult(
                AuthUI.getInstance().createSignInIntentBuilder()
                .setAvailableProviders(providers) //*********
                .setTheme(R.style.AppTheme)
                .build(), MY_REQUEST_CODE
        );
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==MY_REQUEST_CODE){
            IdpResponse response = IdpResponse.fromResultIntent(data);
            if (resultCode== RESULT_OK){
                //Get User
                FirebaseUser user= FirebaseAuth.getInstance().getCurrentUser();
                //Show email on Toast
                Toast.makeText(this, ""+user.getEmail(), Toast.LENGTH_SHORT).show();
                //Set Button signout
                btn_sign_out.setEnabled(true);
            }
            else {
                Toast.makeText(this, ""+response.getError().getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    }
}

Google Firebase

Leave a Reply

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

%d blogcu bunu beğendi: