Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MainActivity : AppCompatActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- val database = FirebaseDatabase.getInstance()
- val myRef = database.getReference("luz-acesa")
- val self = this
- val button = findViewById<TextView>(R.id.lblAviso)
- myRef.addValueEventListener(object : ValueEventListener {
- override fun onDataChange(dataSnapshot: DataSnapshot) {
- val value = dataSnapshot.getValue(Boolean::class.java)
- if (value == true){
- val notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
- val r = RingtoneManager.getRingtone(applicationContext, notification)
- r.play()
- button.setText("Luz Acesa! Cuidado!")
- } else {
- button.setText("Luz Apagada")
- }
- }
- override fun onCancelled(error: DatabaseError) {
- Toast.makeText(self, "Erro: ${error.message}", Toast.LENGTH_SHORT).show()
- }
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement