Firebase数据库未更新

时间:2017-06-09 04:25:13

标签: java android firebase firebase-realtime-database

在我的java应用程序中更改了几个代码后,我的firebase数据库停止了更新信息。我甚至设置了可读的规则以避免任何权限问题。

这是我的规则:

{
  "rules": {
      ".read": true,
      ".write": true
  }
}

这是我的java代码:

package com.bogroup.ucuncuprogram;

import android.content.Context;
import android.widget.Toast;
import com.firebase.client.Firebase;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import static com.facebook.FacebookSdk.getApplicationContext;


public class database{

    public void kullanicikontrol(String kullaniciadi,DatabaseReference mDatabase){

        mDatabase.child("users").child(kullaniciadi).setValue("9999999");
        //mDatabase.child("users").setValue("9999999");

        //chieldref.setValue("9999999");

        Context context = getApplicationContext();
        CharSequence text = kullaniciadi;
        int duration = Toast.LENGTH_LONG;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();

    }
}

对于记录我用调试器检查了它,可以看到我的firebase网址和值kullaniciadi。

编辑:下面我添加了调用此类进行数据库编辑的类。

package com.bogroup.ucuncuprogram;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.InputFilter;
import android.text.InputType;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;
import static com.bogroup.ucuncuprogram.R.id.textView2;


public class ikinciekren extends AppCompatActivity{

    public EditText sayi;
    public TextView sayilar;
    public TextView bilgisayarinattigi;
    public TextView tv;
    public String esassonuc;
    public String bilgisayarsallama;
    public String bilgisayarsallama2;
    public sayisalla sallama;
    public database kullanici;
    public String bilgisayarsayisi;
    private String m_Text = "";
    //private Firebase mRootRef;
    public String idToken;
    public String myuid;
    private DatabaseReference mDatabase;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        ImageView fbphoto;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ikinciekran);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Oyuna başlamak için 4 basamaklı sayınızı giriniz !");
        final EditText input = new EditText(this);
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        int maxLength = 4;
        input.setFilters(new InputFilter[] {new InputFilter.LengthFilter(maxLength)});
        builder.setView(input);
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                m_Text = input.getText().toString();
                tv.setText("Saynız: "+m_Text);
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });

        builder.show();
        sallama = new sayisalla();
        tv = (TextView) findViewById(R.id.textView);
        sayi = (EditText) findViewById(R.id.editText3);
        sayilar = (TextView) findViewById(textView2);
        bilgisayarinattigi = (TextView) findViewById(R.id.textView3);
        mDatabase = FirebaseDatabase.getInstance().getReference();
        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        if (user != null) {
            String name = user.getDisplayName();
            String email = user.getEmail();
            Uri photoUrl = user.getPhotoUrl();
            String uid = user.getUid();
            myuid = uid;
            bilgisayarsayisi = sallama.sayiat();
            sallama.yarat();

            fbphoto = (ImageView) findViewById(R.id.imageView1);
            boolean emailVerified = user.isEmailVerified();
            Picasso.with(this) // Context
                    .load(photoUrl) // URL or file
                    .into(fbphoto);


        }
        sayi.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                sayi.setText("");
            }

        });
    }
    public void sayiat(View v){
        if (v.getId()==R.id.button2){
            if (sayilar.getText().toString().equals("")) {
                String b = sayi.getText().toString();
                esassonuc = sallama.dondur(b,bilgisayarsayisi,0);
                sayilar.setText(esassonuc);
                kullanici = new database();
                kullanici.kullanicikontrol(myuid,mDatabase);
                sayilar.setMovementMethod(new ScrollingMovementMethod());
                final int scrollAmount = sayilar.getLayout().getLineTop(sayilar.getLineCount()) - sayilar.getHeight();
                if (scrollAmount > 0) {
                    sayilar.scrollTo(0, scrollAmount);
                }else {
                    sayilar.scrollTo(0, 0);
                }
            }else{
                if (sayi.getText().length()==4) {
                    String a = sayilar.getText().toString();
                    String b = sayi.getText().toString();
                    esassonuc = sallama.dondur(b,bilgisayarsayisi,0);
                    sayilar.setText(a + "\n" + esassonuc+" aa ");
                    kullanici = new database();
                    kullanici.kullanicikontrol(myuid,mDatabase);
                    sayilar.setMovementMethod(new ScrollingMovementMethod());
                    final int scrollAmount = sayilar.getLayout().getLineTop(sayilar.getLineCount()) - sayilar.getHeight();
                    if (scrollAmount > 0) {
                        sayilar.scrollTo(0, scrollAmount);
                    }else {
                        sayilar.scrollTo(0, 0);
                    }
                }
            }
            if(!"++++".equals(esassonuc)){
                bilgisayarsallama2 = sallama.sayiyarat();
                bilgisayarsallama = sallama.dondur(bilgisayarsallama2,m_Text,1);
                if (bilgisayarinattigi.getText().toString()=="") {
                    bilgisayarinattigi.setText(bilgisayarsallama);
                }else{
                        String a = bilgisayarinattigi.getText().toString();
                        bilgisayarinattigi.setText(a + "\n" + bilgisayarsallama);
                        bilgisayarinattigi.setMovementMethod(new ScrollingMovementMethod());
                        final int scrollAmount = bilgisayarinattigi.getLayout().getLineTop(bilgisayarinattigi.getLineCount()) - bilgisayarinattigi.getHeight();
                        if (scrollAmount > 0) {
                            bilgisayarinattigi.scrollTo(0, scrollAmount);
                        }else {
                            bilgisayarinattigi.scrollTo(0, 0);
                        }
                }
            }else{
                toast("LOST");
            }
        }
    }
    public void cikis(View view) {
        if(view.getId()==R.id.button3){
            FirebaseAuth.getInstance().signOut();
            Intent intent = new Intent(getApplicationContext(),MainActivity.class);
            startActivity(intent);
            finish();
        }
    }
    public void toast(String msg){
        Context context = getApplicationContext();
        CharSequence text = msg;
        int duration = Toast.LENGTH_SHORT;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }
}

1 个答案:

答案 0 :(得分:-1)

请尝试这些手续。

private DatabaseReference ref;
private FirebaseDatabase database;
database = FirebaseDatabase.getInstance();
ref= database.getReference("users");                          
ref.child(kullaniciadi).setValue("9999999");