• Para iniciar é recomendado adicionar o firebase-core • O core já inclui o serviço de Analytics. dependencies { // ... compile 'com.google.firebase:firebase-core:9.4.0' } // ADD THIS AT THE BOTTOM apply plugin: 'com.google.gms.google-services'
FirebaseAuth firebaseAuth) { FirebaseUser user = firebaseAuth.getCurrentUser(); if (user != null) { // User is signed in Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid()); } else { // User is signed out Log.d(TAG, "onAuthStateChanged:signed_out"); } // ... } };
sincroniza todos os clientes conectados em tempo real. • Tempo real • Off-line • Acesso direto via SDK Dependência: compile 'com.google.firebase:firebase-database:9.4.0'
public String email; public User() { // Default constructor required for calls to DataSnapshot.getValue(User.class) } } private void writeNewUser(String userId, String name, String email) { User user = new User(name, email); mDatabase.child("users").child(userId).setValue(user); }
void onDataChange(DataSnapshot dataSnapshot) { // Get Post object and use the values to update the UI Post post = dataSnapshot.getValue(Post.class); // ... } @Override public void onCancelled(DatabaseError databaseError) { // Getting Post failed, log a message Log.w(TAG, "loadPost:onCancelled", databaseError.toException()); // ... } }; mPostReference.addValueEventListener(postListener);
new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { // Get user value User user = dataSnapshot.getValue(User.class); // ... } @Override public void onCancelled(DatabaseError databaseError) { Log.w(TAG, "getUser:onCancelled", databaseError.toException()); } });
reference from our app StorageReference storageRef = storage.getReferenceFromUrl("gs://<your-bucket-name>"); // Create a reference to "mountains.jpg" StorageReference mountainsRef = storageRef.child("mountains.jpg"); // Create a reference to 'images/mountains.jpg' StorageReference mountainImagesRef = storageRef.child("images/mountains.jpg"); // While the file names are the same, the references point to different files mountainsRef.getName().equals(mountainImagesRef.getName()); // true mountainsRef.getPath().equals(mountainImagesRef.getPath()); // false 1 A URL pode ser obtida na seção Storage do Firebase console
que estão na memória e arquivos locais. Uri file = Uri.fromFile(new File("path/to/images/rivers.jpg")); StorageReference riversRef = storageRef.child("images/"+file.getLastPathSegment()); uploadTask = riversRef.putFile(file); // Register observers to listen for when the download is done or if it fails uploadTask.addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception exception) { // Handle unsuccessful uploads } }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL. Uri downloadUrl = taskSnapshot.getDownloadUrl(); } });
em um arquivo local. E ele também gera uma URL para compartilhamento. StorageReference islandRef = storageRef.child("images/island.jpg"); File localFile = File.createTempFile("images", "jpg"); islandRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() { @Override public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) { // Local temp file has been created } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception exception) { // Handle any errors } });
notificações entre plataformas diferentes. • Direcionamento versátil de mensagens • Suporte a mensagens de dados e notificações • Mensagens ascendentes de aplicativos cliente Dependência: compile 'com.google.firebase:firebase-messaging:9.4.0'
criando um serviço que extenda de FirebaseInstanceIdService. E para processar as mensagens enviadas pelo FCM, é preciso criar um serviço que extenda de FirebaseMessagingService.
Handle FCM messages here. // Not getting messages here? See why this may be: https://goo.gl/39bRNJ Log.d(TAG, "From: " + remoteMessage.getFrom()); // Check if message contains a data payload. if (remoteMessage.getData().size() > 0) { Log.d(TAG, "Message data payload: " + remoteMessage.getData()); } // Check if message contains a notification payload. if (remoteMessage.getNotification() != null) { Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); } // Also if you intend on generating your own notifications as a result of a received FCM // message, here is where that should be initiated. See sendNotification method below. }
é um serviço beta. • Monitore erros fatais e não fatais • Colete os dados necessários para diagnosticar problemas • Integre ao Analytics Dependência: compile 'com.google.firebase:firebase-crash:9.4.0'