{ "rules": { ".read": true, ".write": true } }
{ "project_info": { "project_number": "271840981827", "firebase_url": "https://fir-de130.firebaseio.com", "project_id": "fir-de130", "storage_bucket": "fir-de130.appspot.com" }, "client": [ { "client_info": { "mobilesdk_app_id": "1:271840981827:android:b2beb7634256e5c3", "android_client_info": { "package_name": "com.srikanthtechnologies.firebaseapp" } }, "oauth_client": [ { "client_id": "271840981827-d9p9hfh76k2hcs2jtte83d2h41le5vsd.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { "current_key": "AIzaSyCzLC0rgvAFoHc4a-oGUML9OfDiYOPljjc" } ], "services": { "analytics_service": { "status": 1 }, "appinvite_service": { "status": 1, "other_platform_oauth_client": [] }, "ads_service": { "status": 2 } } } ], "configuration_version": "1" }
package com.srikanthtechnologies.firebaseapp; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; import com.google.firebase.database.ValueEventListener; public class MainActivity extends Activity { FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference rootRef = database.getReference(); DatabaseReference courseRef = rootRef.child("course"); EditText editCourseName; TextView textCourseName; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editCourseName = (EditText) findViewById(R.id.editCourseName); textCourseName = (TextView) findViewById(R.id.textCourseName); // handle value event for course node courseRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { textCourseName.setText(dataSnapshot.getValue().toString()); } @Override public void onCancelled(DatabaseError databaseError) { } }); } public void updateCourse(View v) { // Write a value to course node courseRef.setValue(editCourseName.getText().toString()); Toast.makeText(this,"Updated Course", Toast.LENGTH_LONG).show(); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:orientation="vertical" tools:context=".MainActivity"> <TextView android:id="@+id/textCourseName" android:gravity="center" android:textColor="#ff0000" android:textAppearance="?android:textAppearanceMedium" android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:id="@+id/editCourseName" android:hint="Course Name" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:onClick="updateCourse" android:text="Update" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.srikanthtechnologies.firebaseapp"> <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> </application> </manifest>
apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.3" defaultConfig { applicationId "com.srikanthtechnologies.firebaseapp" minSdkVersion 16 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.google.firebase:firebase-database:10.0.1' testCompile 'junit:junit:4.12' } apply plugin: 'com.google.gms.google-services'