In Firebase:
In Database > Rules, I have the following:
{ "rules": { ".read": "true", ".write": "true" } }
On Android:
I already imported
compile 'com.google.firebase: firebase-database: 9.6.1'
I have the following layout from which I request the data:
content_user_home.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:id="@+id/content_user_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.didierzuniga.domix.view.UserHomeActivity"
tools:showIn="@layout/app_bar_user_home">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditTextGrey"
android:layout_marginTop="@dimen/edittext_margin_createaccount">
<android.support.design.widget.TextInputEditText
android:id="@+id/idFrom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_from" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditTextGrey"
android:layout_marginTop="@dimen/edittext_margin_createaccount">
<android.support.design.widget.TextInputEditText
android:id="@+id/idTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_to" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditTextGrey"
android:layout_marginTop="@dimen/edittext_margin_createaccount">
<android.support.design.widget.TextInputEditText
android:id="@+id/idOrderTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_order_title" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditTextGrey"
android:layout_marginTop="@dimen/edittext_margin_createaccount">
<android.support.design.widget.TextInputEditText
android:id="@+id/idOrderDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_order_description" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditTextGrey"
android:layout_marginTop="@dimen/edittext_margin_createaccount">
<android.support.design.widget.TextInputEditText
android:id="@+id/idMoneyToPay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_payment" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/button_request_order"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/button_text_request"/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
I want to take the TextInputEditText
given by the user and save them in FirebaseDatabase .
What I have so far in backend is the following:
DomixApplication.java package com.didierzuniga.domix;
import android.app.Application;
import android.content.Context;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class DomixApplication extends Application {
DatabaseReference orderReference;
Context context;
@Override
public void onCreate() {
super.onCreate();
FirebaseDatabase frbDatabase = FirebaseDatabase.getInstance();
frbDatabase.setPersistenceEnabled(true);
orderReference = frbDatabase.getReference("order");
this.context = this;
}
public DatabaseReference getOrderReference() {
return orderReference;
}
public Context getContext() {
return context;
}
}
UserHomeActivity.class
public class UserHomeActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
DomixApplication app;
DatabaseReference orderReference;
@Bind(R.id.idFrom) TextInputEditText from;
@Bind(R.id.idTo) TextInputEditText to;
@Bind(R.id.idOrderTitle) TextInputEditText orderTitle;
@Bind(R.id.idOrderDescription) TextInputEditText description;
@Bind(R.id.idMoneyToPay) TextInputEditText payment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ButterKnife.bind(this);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open_user, R.string.navigation_drawer_close_user);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@OnClick(R.id.button_request_order)
public void sendRequest(){
String vFrom = from.getText().toString().trim();
String vTo = to.getText().toString().trim();
String vOrderTitle = orderTitle.getText().toString().trim();
String vDescription = description.getText().toString().trim();
String vPayment = payment.getText().toString().trim();
Order order = new Order(vFrom, vTo, vOrderTitle, vDescription, vPayment);
orderReference.push().setValue(order);
}
...
Where should I call the url address of FirebaseDatabase
?
And what else should I add?