Hi All
I know that there has been a lot of questions relating to this question. I have tried using AnswerCall library but alas it does not seem to work on all devices.
I have researched this topic an there seems to be away by using Intents;
The above code snipit is from http://stackoverflow.com/questions/15481524/how-to-programatically-answer-end-a-call-in-android-4-1 and seems to show how to simulate a human would answering a call via their headset.
I have attempted to convert this to B4A but I an not a Java Expert and it does not work for me.
Does anyone want to have a go at this and help. I am struggling with the putextra multiple values for the Key Events. There are a lot of these examples and if we all could learn how to translate them to b4a with the tools to hand it would benefit the wider community.
Regards
John.
I know that there has been a lot of questions relating to this question. I have tried using AnswerCall library but alas it does not seem to work on all devices.
I have researched this topic an there seems to be away by using Intents;
B4X:
public void answerPhoneHeadsethook(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.d(TAG, "Incoming call from: " + number);
Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
try {
context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
Log.d(TAG, "ACTION_MEDIA_BUTTON broadcasted...");
}
catch (Exception e) {
Log.d(TAG, "Catch block of ACTION_MEDIA_BUTTON broadcast !");
}
Intent headSetUnPluggedintent = new Intent(Intent.ACTION_HEADSET_PLUG);
headSetUnPluggedintent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
headSetUnPluggedintent.putExtra("state", 1); // 0 = unplugged 1 = Headset with microphone 2 = Headset without microphone
headSetUnPluggedintent.putExtra("name", "Headset");
// TODO: Should we require a permission?
try {
context.sendOrderedBroadcast(headSetUnPluggedintent, null);
Log.d(TAG, "ACTION_HEADSET_PLUG broadcasted ...");
}
catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
Log.d(TAG, "Catch block of ACTION_HEADSET_PLUG broadcast");
Log.d(TAG, "Call Answered From Catch Block !!");
}
Log.d(TAG, "Answered incoming call from: " + number);
}
Log.d(TAG, "Call Answered using headsethook");
}
The above code snipit is from http://stackoverflow.com/questions/15481524/how-to-programatically-answer-end-a-call-in-android-4-1 and seems to show how to simulate a human would answering a call via their headset.
I have attempted to convert this to B4A but I an not a Java Expert and it does not work for me.
B4X:
Dim iB, iH As Intent
Dim Broadcast As BroadCastReceiver
Broadcast.Initialize("BR")
iB.Initialize("android.intent.action.MEDIA_BUTTON","")
iB.PutExtra("android.intent.extra.KEY_EVENT",1 & "," & KeyCodes.KEYCODE_HEADSETHOOK) ' ACTION_UP
Log(iB.Action & " - " & iB.ExtrasToString)
Broadcast.sendOrderedBroadcast(iB,"android.permission.CALL_PRIVILEGED")
iH.Initialize("android.intent.action.HEADSET_PLUG","")
iH.Flags = 1073741824 ' FLAG_RECEIVER_REGISTERED_ONLY
iH.PutExtra("state",1) ' 0 = unplugged 1 = Headset with microphone 2 = Headset without microphone
iH.PutExtra("name","Headset")
Log(iH.Action & " - " & iH.ExtrasToString)
Broadcast.sendOrderedBroadcast(iH,Null)
Does anyone want to have a go at this and help. I am struggling with the putextra multiple values for the Key Events. There are a lot of these examples and if we all could learn how to translate them to b4a with the tools to hand it would benefit the wider community.
Regards
John.