Skip to content

Instantly share code, notes, and snippets.

@yakutozcan
Created November 7, 2017 19:57
Show Gist options
  • Save yakutozcan/e9da84dd34327fe97962e4dc4728e7fc to your computer and use it in GitHub Desktop.
Save yakutozcan/e9da84dd34327fe97962e4dc4728e7fc to your computer and use it in GitHub Desktop.
package haydut.firebaseled;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class MainActivity extends AppCompatActivity {
int i = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button BTNLed = (Button)findViewById(R.id.button3);
//Firebase bağlantısını yapıyoruz
FirebaseDatabase database = FirebaseDatabase.getInstance();
//LedStatus alanına işlem yapacağız
final DatabaseReference myRef = database.getReference("LEDStatus");
BTNLed.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(i%2==0){
//i çift ise 1 yaz
myRef.setValue(1);
}else{
//i tek ise 0 yaz
myRef.setValue(0);
}
i++;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment