Reputation: 127
I tried looking for a plugin, but couldn't find one, so I tried making my own. I want to turn silent mode on with a JavaScript command, but I get undefined method on getSystemService. I think there might be something wrong with my imports. Please help.
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
public class AudioControl extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("echo")) {
AudioManager audiomanage = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audiomanage.setRingerMode(AudioManager.RINGER_MODE_SILENT);
String message = args.getString(0);
this.echo(message, callbackContext);
return true;
}
return false;
}
}
Upvotes: 1
Views: 1182
Reputation: 49929
Something I can think of is that the context is not right. Try this:
cordova.getActivity().getSystemService(Context.AUDIO_SERVICE)
What version of PhoneGap / Cordova are you using?
Exluded issues:
echo
as action is correct/res/xml/config.xml
the settings are correct/AndroidMenifest.xml
has the correct settingsUpvotes: 2