Skip to content

Instantly share code, notes, and snippets.

View AndroidBullOfficial's full-sized avatar

Waqas Younis AndroidBullOfficial

View GitHub Profile
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="@android:color/white">
</solid>
<corners
android:bottomLeftRadius="@dimen/_25sdp"
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
tools:context=".SignUp">
package com.arslan6015.demodatabase;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
// Read from the database
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
String value = dataSnapshot.getValue(String.class);
Log.d(TAG, "Value is: " + value);
}
FirebaseDatabase database = FirebaseDatabase.getInstance();
//you can also use .child() to get the same results
DatabaseReference myRef = database.getReference("message").child("java").child("user");
myRef.setValue("Hello, Worldd!");
// Write a message to the database
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message/java/user"); //set path to get the multiple dropdown nodes
myRef.setValue("Hello, World!");
// Write a message to the database
FirebaseDatabase database = FirebaseDatabase.getInstance(); // Get the database instance and store into object
DatabaseReference myRef = database.getReference("message"); // getReference() get the refrence if the refrence is already creted... if refrence is not created then it will create a new refrence here
myRef.setValue("Hello, World!"); // assign value to the particular refrence.
// Validates timestamp is not a future value
{
“rules”: {
“posts”: {
“$uid”: {
“timestamp”: {
“.validate”: “newData.val() <= now”
}
}
}
// Checks presence of child attributes
{
“rules”: {
“posts”: {
“$uid”: {
“.validate”: “newData.hasChildren([‘username’, ‘timestamp’])”
}
}
}
}
// Validates string datatype and length range
{
“rules”: {
“posts”: {
“$uid”: {
“.validate”: “newData.isString()
&& newData.val().length > 0
&& newData.val().length <= 140”
}
}