I used the AudioManager Method: setWiredDeviceConnectionState to disable the headset on my device. It worked fine until I came across some newer models and now it does not work. I assume this is because the Hack does not work anymore. Is there any upgrade to the previous hack or any other ways to disable the headset from the device? I need to be able to play a tone via the In-Call_Speaker while a headset is plugged it. Please Help!!!
This is the exception it gives when ran:
W/System: ClassLoader referenced unknown path: /data/app/com.example.raptorroboticstest-2/lib/arm64
W/System.err: java.lang.NoSuchMethodException: setWiredDeviceConnectionState [int, int, class java.lang.String]
This is the method to disable/enable the headset:
AudioManager manager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
try {
Class<?> cl = Class.forName("android.media.AudioManager");
setWiredDeviceConnectionState = cl.getMethod("setWiredDeviceConnectionState", new Class[]{Integer.TYPE, Integer.TYPE, String.class});
//4 is for the headset with microphone 8 is for headset without microphone
//0 is for off and 1 is for on
setWiredDeviceConnectionState.invoke(manager, new Object[]{4, 0, "device"});
setWiredDeviceConnectionState.invoke(manager, new Object[]{8, 0, "device"});
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Aucun commentaire:
Enregistrer un commentaire