Display Snackbar when message is received
This commit is contained in:
@@ -12,6 +12,8 @@ import android.util.Log;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ToggleButton;
|
import android.widget.ToggleButton;
|
||||||
|
|
||||||
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
@@ -22,6 +24,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String msg = intent.getStringExtra("STATE");
|
String msg = intent.getStringExtra("STATE");
|
||||||
Log.i(TAG, "Received " + msg);
|
Log.i(TAG, "Received " + msg);
|
||||||
|
View contextView = findViewById(R.id.toggleButton);
|
||||||
|
Snackbar.make(contextView, "Received " + msg, Snackbar.LENGTH_LONG)
|
||||||
|
.show();
|
||||||
stateButton.setChecked(!msg.equals("OFF"));
|
stateButton.setChecked(!msg.equals("OFF"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user