I want to send message from one device to another, i send and Toast show my message. I try to do:
if(message.equals("mute")){
if(IsAudioOn){
IsAudioOn = false;
amanager.setStreamMute(AudioManager.STREAM_MUSIC, false); // for unmute}else{
IsAudioOn = true;
amanager.setStreamMute(AudioManager.STREAM_MUSIC, true); //for mute
}
for making instructions for device what he should do when he gets a typical message, but this didn’t work,
Here are some of my methods from one device from which I try to control another:
public void sendMessage(String message) {
if (bBluetooth) {
bt.send(message, true);
} else {
wiFiP2pService.sendData(message);
}
}
This works, I send the string MESSAGE and it shows on another device in TOAST method.
Here is my dataReceiver is on second device
bt.setOnDataReceivedListener(new BluetoothSPP.OnDataReceivedListener() {
public void onDataReceived(byte[] data, String message) {
showToastMessage(message, 300);
AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
if(message.equals("MUTE")){
if(IsAudioOn){
IsAudioOn = false;
amanager.setStreamMute(AudioManager.STREAM_MUSIC, false); // for unmute}else{
IsAudioOn = true;
amanager.setStreamMute(AudioManager.STREAM_MUSIC, true); //for mute
}
}else if(message.equals("VOLUME DOWN")){
amanager.setStreamVolume(
AudioManager.STREAM_MUSIC,
amanager.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
0);
}
}
});
as u see I try to detect like
message.equals("string")
but this does not work, Any help appreciated..
As per doc, setStreamMute
–
This method should only be used by applications that replace the platform-wide management of audio settings or the main telephony application.
If you need to mute all sound on device, please take a look on possible solutions for that problem.
Answered By — Divers
Answer Checked By — Gilberto Lyons (FixIt Admin)
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0