tags: Android Bluetooth Call mechanism Bluetooth phone
Introduction: recently encountered a need to write a APP on-board system, you need to control your calls on your phone. Previously had contact with Bluetooth, so a little bit to understand.
first car phone is connected, the phone belonging to the service side, on-board system belongs to the client. In the Android source code to achieve the client to the server Bluetooth phone hang up and answer. Code: /frameworks/base/core/java/android/bluetooth/BluetoothHeadsetClient.java
There is a corresponding function to answer the call and hang up.
answer the phone
/**
* Accepts a call
*
* @param device remote device
* @param flag action policy while accepting a call. Possible values {@link #CALL_ACCEPT_NONE},
* {@link #CALL_ACCEPT_HOLD}, {@link #CALL_ACCEPT_TERMINATE}
* @return <code>true</code> if command has been issued successfully; <code>false</code>
* otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.
*/
public boolean acceptCall(BluetoothDevice device, int flag) {
if (DBG) log("acceptCall()");
final IBluetoothHeadsetClient service = mService;
if (service != null && isEnabled() && isValidDevice(device)) {
try {
return service.acceptCall(device, flag);
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(new Throwable()));
}
}
if (service == null) Log.w(TAG, "Proxy not attached to service");
return false;
}
hang up the phone
/**
* Rejects a call.
*
* @param device remote device
* @return <code>true</code> if command has been issued successfully; <code>false</code>
* otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.
*
* <p>Feature required for successful execution is being reported by: {@link
* #EXTRA_AG_FEATURE_REJECT_CALL}. This method invocation will fail silently when feature is not
* supported.</p>
*/
public boolean rejectCall(BluetoothDevice device) {
if (DBG) log("rejectCall()");
final IBluetoothHeadsetClient service = mService;
if (service != null && isEnabled() && isValidDevice(device)) {
try {
return service.rejectCall(device);
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(new Throwable()));
}
}
if (service == null) Log.w(TAG, "Proxy not attached to service");
return false;
}
In addition to call state management in: /frameworks/base/core/java/android/bluetooth/BluetoothHeadsetClientCall.java
here acquisition device is connected, it has been a call.
Get the current call status
/**
* Gets call's current state.
*
* @return state of this particular phone call.
*/
public int getState() {
return mState;
}
/**
* Gets call's device.
*
* @return call device.
*/
public BluetoothDevice getDevice() {
return mDevice;
}
At first I was developing on Android studio and found no api and maybe a jar package, maybe later found hidden classes are Android api, application systems can only call party applications not take. If you want to use the reflection mechanism can be used to invoke.
First, the connection step 1. Double-click the Bluetooth button as shown below: 2, add equipment 3, open the android phone Bluetooth and device visibility, settings - "unlimited and network...
What is Bluetooth? Before turning on Bluetooth Spec v5.2-based learning, let’s first understand what Bluetooth is? What practical applications does Bluetooth exist in our daily lives? Bluetooth ...
Tips: This article is mainly for Bluetooth devices operate other devices tested yet. It encapsulates a series of Bluetooth operation: 1, search for Bluetooth Class has been packaged, can directly call...
Why 80% of the code can not do farming architect? >>> Recent projects busy, finally have free time to write about things. Android did believe all know that the phone system is var...
Reprinted: http://blog.csdn.net/goohong/article/details/7983558 Phone management isAndroid One of the important services supported by the system, providing functions such as answering calls, send...
Bowen series: (1)Android phone with a Bluetooth module joint commissioning (a) - Bluetooth serial communication module (2)Android phone with a Bluetooth module joint commissioning (b) - Single-chip Bl...
A recent voice project requires that the car terminal can use Bluetooth to make voice calls to contacts in the phone address book. To realize this function, you need to upload the address book of the ...
Android Bluetooth Development (1) - Traditional Bluetooth Chat Room Project engineering BluetoothDemo In the previous chapter, we have learned the development of traditional Bluetooth, this chapter, l...
First, the version before Android 6.0 Get the Bluetooth adapter BluetoothAdpater or Second, the version after Android 6.0 Turn on Bluetooth to get Reprinted at: https://www.jianshu.com/p/d9ffcc9773b4...