I have a probleme while developping an application. I'm calling the "onReceive" method of my "BroadcastReceiver" from "onCreate" method of the service, and it works fine, but the problem is that i would like to change the volume MODE from MEDIA to RING. I've made a lot of researches but i didn't find a solution. This is my Boadcast class, (just trying to catch the media volume and switch it to ring volume control), ...
final class ScreenReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
Log.i("CIRUS ON RECEIVE", "je suis dans la methode onReceive");
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
// stuff
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
AudioManager mAudioManager;
mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setStreamVolume(AudioManager.STREAM_RING, 7, 0);
Log.i("Cirus OnReceive ScreenReceiver", "Code executé -> "+AudioManager.STREAM_RING);
}
}
}
Of course, the manifest is well configured.
Thank you all in advance.