android -- 蓝牙 bluetooth (五)接电话与听音乐

时间:2025-01-26 17:53:53
  • static jboolean connectA2dpNative(JNIEnv *env, jobject object, jbyteArray address) {  
  •   jbyte *addr;  
  •   bt_bdaddr_t * btAddr;  
  •   bt_status_t status;  
  •   
  •   ALOGI("%s: sBluetoothA2dpInterface: %p", __FUNCTION__, sBluetoothA2dpInterface);  
  •   if (!sBluetoothA2dpInterface) return JNI_FALSE;  
  •   
  •   addr = env->GetByteArrayElements(address, NULL);  
  •   btAddr = (bt_bdaddr_t *) addr;  
  •   if (!addr) {  
  •       jniThrowIOException(env, EINVAL);  
  •       return JNI_FALSE;  
  •   }  
  •   if ((status = sBluetoothA2dpInterface->connect((bt_bdaddr_t *)addr)) != BT_STATUS_SUCCESS) {  
  •       ALOGE("Failed HF connection, status: %d", status);  
  •   }  
  •   env->ReleaseByteArrayElements(address, addr, 0);  
  •   return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;