0

I'm trying to retrieve my temperature data from the Firebase, but instead nothing appears. Not to sure on what the issue is and how to approach it. I feel as if there is a issue with my Firebase authentication and the ability to give it access to read from the database.

The error prompt:

W/RenderThread: type=1400 audit(0.0:12802165): avc: denied { read } for name="u:object_r:vendor_default_prop:s0" dev="tmpfs" ino=15849 scontext=u:r:untrusted_app_27:s0:c512,c768 tcontext=u:object_r:vendor_default_prop:s0 tclass=file permissive=0

TempHistory.java:

package com.example.dialg.projectlayouts;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.TextView;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
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;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.Query;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class TempHistory extends AppCompatActivity {
FirebaseAuth mAuth;
FirebaseAuth.AuthStateListener mAuthListener;
private FirebaseDatabase database;
private DatabaseReference myRef;


private static final String TAG = "TempHistory";
DataStructure mData;
private TextView temperature;
   // private TextView timestamp;

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

    temperature = (TextView) findViewById(R.id.readTemperature);

    //Back button
    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle("Previous Saves");


    mAuth = FirebaseAuth.getInstance();
    database = FirebaseDatabase.getInstance();
    FirebaseUser user = mAuth.getCurrentUser();
    String userID = user.getUid();


    myRef = database.getReference().child(userID).child("DataStructure");

    //Reads from Database Functions
    retrieveData();
    }


private void retrieveData(){
    myRef.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
            DataStructure ds = dataSnapshot.getValue(DataStructure.class);
            temperature.setText("Previous Temperature (in celsius): " +ds.getTemperature());

            //timestamp.setText(convertTimestamp(ds.getTimestamp()));
        }

      /*  private String convertTimestamp(String timestamp){

            long yourSeconds = Long.valueOf(timestamp);
            Date mDate = new Date(yourSeconds * 1000);
            DateFormat df = new SimpleDateFormat("dd MMM yyyy hh:mm:ss");
            return df.format(mDate);
        }
            */

        @Override
        public void onChildChanged(@NonNull DataSnapshot dataSnapshot, 
        @Nullable String s) {
            DataStructure ds = dataSnapshot.getValue(DataStructure.class);
            temperature.setText("Previous Temperature (in celsius): " 
            +ds.getTemperature());

          //  timestamp.setText(convertTimestamp(ds.getTimestamp()));

        }

        @Override
        public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
    myRef.addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            List<DataStructure> arraylist = new ArrayList<>();
            if (dataSnapshot !=null && dataSnapshot.getValue() !=null){

                for (DataSnapshot a : dataSnapshot.getChildren()) {
                    DataStructure dataStructure = new DataStructure();
                    dataStructure.setTemperature(a.getValue(DataStructure.class).getTemperature());
                    arraylist.add(dataStructure);

                }
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}
}

Datastructure:

package com.example.dialg.projectlayouts;

public class DataStructure {
private String temperature;
//private String timestamp;

public DataStructure() {

}


public DataStructure(String temperature) {
    this.temperature = temperature;
    //this.timestamp = timestamp;
}

public String getTemperature() {
    return temperature;
}

public void setTemperature(String temperature) {
    this.temperature = temperature;
}

}

I've even changed the rules to writing and reading database to fit the proper credentials.

{
"rules": {
".read": "auth !=null",
".write": "auth !=null"
}
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

0

Make sure app name and client id are same as in firebase console.

If you are not sure re-download google-services.json from your project's console and add it your project.

apache
  • 35
  • 1
  • 1
  • 8