I'm trying to program a hands free call when a user push a button.
Up to now, I'm able to make a call but I can't enable hands free mode.
I tried this answer but it doesn't work for me.
This is a sample of my code:
private void callCaregiver(String number){
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+number.trim()));
enableHandsFree();
startActivity(callIntent);
}
private void enableHandsFree(){
Class audioSystemClass = Class.forName("android.media.AudioSystem");
Method setForceUse = audioSystemClass.getMethod("setForceUse", int.class, int.class);
// First 1 == FOR_MEDIA, second 1 == FORCE_SPEAKER. To go back to the default
// behavior, use FORCE_NONE (0).
setForceUse.invoke(null, 1, 1);
}
Does anybody any know another way to make it work?