I'm trying to send a request to server and when i get response from server I want to change the phone from silent mode into normal mode. I'm using retrofit and I'm new at all of this.
Here is how I make request and process response:
Call<ServerResponse3> response3 = requestInterface.chec(ProfileFragment.Global.email);
response3.enqueue(new Callback<ServerResponse3>() {
@Override
public void onResponse(Call<ServerResponse3> call, retrofit2.Response<ServerResponse3> response3) {
ServerResponse3 resp = response3.body();
Toast.makeText(BService.this, resp.getResult(), LENGTH_LONG).show();
Toast.makeText(BService.this, ProfileFragment.Global.ID, LENGTH_LONG).show();
final AudioManager mode = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
if (resp.getResult().contains("true")) {
//Normal Mode Programatically
mode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
} else {
//Silent Mode Programatically
mode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
}
And here is the interface part:
@GET("project5/web/normal")
Call<ServerResponse3> chec (@Query("email") String email);
So am I doing this right or there is something wrong?
Use activity name for context like this:
final AudioManager mode = (AudioManager) YourActivityName.this.getSystemService(Context.AUDIO_SERVICE);