當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothProfile.HEADSET屬性代碼示例

本文整理匯總了Java中android.bluetooth.BluetoothProfile.HEADSET屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothProfile.HEADSET屬性的具體用法?Java BluetoothProfile.HEADSET怎麽用?Java BluetoothProfile.HEADSET使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.bluetooth.BluetoothProfile的用法示例。


在下文中一共展示了BluetoothProfile.HEADSET屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startBluetooth

private void startBluetooth() {
	if (isBluetoothConnected) {
		Log.e("[Bluetooth] Already started, skipping...");
		return;
	}
	
	mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
	
	if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) {
		if (mProfileListener != null) {
			Log.w("[Bluetooth] Headset profile was already opened, let's close it");
			mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
		}
		
		mProfileListener = new BluetoothProfile.ServiceListener() {
			public void onServiceConnected(int profile, BluetoothProfile proxy) {
			    if (profile == BluetoothProfile.HEADSET) {
			        Log.d("[Bluetooth] Headset connected");
			        mBluetoothHeadset = (BluetoothHeadset) proxy;
			        isBluetoothConnected = true;
			    }
			}
			public void onServiceDisconnected(int profile) {
			    if (profile == BluetoothProfile.HEADSET) {
			        mBluetoothHeadset = null;
			        isBluetoothConnected = false;
			        Log.d("[Bluetooth] Headset disconnected");
			        LinphoneManager.getInstance().routeAudioToReceiver();
			    }
			}
		};
		boolean success = mBluetoothAdapter.getProfileProxy(mContext, mProfileListener, BluetoothProfile.HEADSET);
		if (!success) {
			Log.e("[Bluetooth] getProfileProxy failed !");
		}
	} else {
		Log.w("[Bluetooth] Interface disabled on device");
	}
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:39,代碼來源:BluetoothManager.java

示例2: onServiceDisconnected

@Override
public void onServiceDisconnected(int profile) {
    Log.e("blueHeadsetListener", "onServiceDisconnected:" + profile);
    if (profile == BluetoothProfile.A2DP) {
        voiceMediator.setBluetoothA2dp(null);
    } else if (profile == BluetoothProfile.HEADSET) {
        voiceMediator.setBluetoothHeadset(null);
    }
}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:9,代碼來源:AssistantService.java

示例3: onServiceConnected

@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
    Log.e("blueHeadsetListener", "onServiceConnected:" + profile);
    if (profile == BluetoothProfile.A2DP) {
        voiceMediator.setBluetoothA2dp((BluetoothA2dp) proxy);
    } else if (profile == BluetoothProfile.HEADSET) {
        voiceMediator.setBluetoothHeadset((BluetoothHeadset) proxy);
    }
}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:9,代碼來源:AssistantService.java

示例4: onServiceConnected

@Override
// Called to notify the client when the proxy object has been connected to the service.
// Once we have the profile proxy object, we can use it to monitor the state of the
// connection and perform other operations that are relevant to the headset profile.
public void onServiceConnected(int profile, BluetoothProfile proxy) {
    if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) {
        return;
    }
    Log.d(TAG, "BluetoothServiceListener.onServiceConnected: BT state=" + bluetoothState);
    // Android only supports one connected Bluetooth Headset at a time.
    bluetoothHeadset = (BluetoothHeadset) proxy;
    updateAudioDeviceState();
    Log.d(TAG, "onServiceConnected done: BT state=" + bluetoothState);
}
 
開發者ID:nhancv,項目名稱:nc-android-webrtcpeer,代碼行數:14,代碼來源:BluetoothManager.java

示例5: onServiceDisconnected

@Override
/** Notifies the client when the proxy object has been disconnected from the service. */
public void onServiceDisconnected(int profile) {
    if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) {
        return;
    }
    Log.d(TAG, "BluetoothServiceListener.onServiceDisconnected: BT state=" + bluetoothState);
    stopScoAudio();
    bluetoothHeadset = null;
    bluetoothDevice = null;
    bluetoothState = State.HEADSET_UNAVAILABLE;
    updateAudioDeviceState();
    Log.d(TAG, "onServiceDisconnected done: BT state=" + bluetoothState);
}
 
開發者ID:nhancv,項目名稱:nc-android-webrtcpeer,代碼行數:14,代碼來源:BluetoothManager.java

示例6: onServiceConnected

/**
 * 監聽到藍牙設備連接
 * @param profile
 * @param headset
 */
@Override
public void onServiceConnected(int profile, BluetoothProfile headset) {
    if (profile == BluetoothProfile.HEADSET) {
        LogUtil.e("onServiceConnected " + profile + " " + headset);
        mBluetoothProfile = headset;

        List<BluetoothDevice> devices = headset.getConnectedDevices();
        headsetPlugged(devices != null && devices.size() > 0);
    }
}
 
開發者ID:wzc25151,項目名稱:lrs_android,代碼行數:15,代碼來源:AgoraActivity.java

示例7: onServiceConnected

@Override
// Called to notify the client when the proxy object has been connected to the service.
// Once we have the profile proxy object, we can use it to monitor the state of the
// connection and perform other operations that are relevant to the headset profile.
public void onServiceConnected(int profile, BluetoothProfile proxy) {
  if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) {
    return;
  }
  Log.d(TAG, "BluetoothServiceListener.onServiceConnected: BT state=" + bluetoothState);
  // Android only supports one connected Bluetooth Headset at a time.
  bluetoothHeadset = (BluetoothHeadset) proxy;
  updateAudioDeviceState();
  Log.d(TAG, "onServiceConnected done: BT state=" + bluetoothState);
}
 
開發者ID:Piasy,項目名稱:AppRTC-Android,代碼行數:14,代碼來源:AppRTCBluetoothManager.java

示例8: onServiceDisconnected

@Override
/** Notifies the client when the proxy object has been disconnected from the service. */
public void onServiceDisconnected(int profile) {
  if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) {
    return;
  }
  Log.d(TAG, "BluetoothServiceListener.onServiceDisconnected: BT state=" + bluetoothState);
  stopScoAudio();
  bluetoothHeadset = null;
  bluetoothDevice = null;
  bluetoothState = State.HEADSET_UNAVAILABLE;
  updateAudioDeviceState();
  Log.d(TAG, "onServiceDisconnected done: BT state=" + bluetoothState);
}
 
開發者ID:Piasy,項目名稱:AppRTC-Android,代碼行數:14,代碼來源:AppRTCBluetoothManager.java

示例9: onServiceConnected

@Override
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            try {
                if (profile == BluetoothProfile.HEADSET) {
//                    bh = (BluetoothHeadset) proxy;
//                    if (bh.getConnectionState(mTouchObject.bluetoothDevice) != BluetoothProfile.STATE_CONNECTED){
//                        bh.getClass()
//                                .getMethod("connect", BluetoothDevice.class)
//                                .invoke(bh, mTouchObject.bluetoothDevice);
//                    }

                } else if (profile == BluetoothProfile.A2DP) {
                    /**使用A2DP的協議連接藍牙設備(使用了反射技術調用連接的方法)*/
                    a2dp = (BluetoothA2dp) proxy;
                    if (a2dp.getConnectionState(currentBluetoothDevice) != BluetoothProfile.STATE_CONNECTED) {
                        a2dp.getClass()
                                .getMethod("connect", BluetoothDevice.class)
                                .invoke(a2dp, currentBluetoothDevice);
                        Toast.makeText(MainActivity.this,"請播放音樂",Toast.LENGTH_SHORT).show();
                        getBondedDevices();
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
 
開發者ID:LiuJunb,項目名稱:BlueToothEatPhone,代碼行數:27,代碼來源:MainActivity.java

示例10: setUp

@Before
public void setUp() {
    ShadowLog.stream = System.out;
    context = ShadowApplication.getInstance().getApplicationContext();
    mockedAppRtcAudioManager = mock(AppRTCAudioManager.class);
    mockedAudioManager = mock(AudioManager.class);
    mockedBluetoothHeadset = mock(BluetoothHeadset.class);
    mockedBluetoothDevice = mock(BluetoothDevice.class);
    mockedBluetoothDeviceList = new LinkedList<BluetoothDevice>();

    // Simulate that bluetooth SCO audio is available by default.
    when(mockedAudioManager.isBluetoothScoAvailableOffCall()).thenReturn(true);

    // Create the test object and override protected methods for this test.
    bluetoothManager = new AppRTCBluetoothManager(context, mockedAppRtcAudioManager) {
        @Override
        protected AudioManager getAudioManager(Context context) {
            Log.d(TAG, "getAudioManager");
            return mockedAudioManager;
        }

        @Override
        protected void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
            Log.d(TAG, "registerReceiver");
            if (filter.hasAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)
                    && filter.hasAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) {
                // Gives access to the real broadcast receiver so the test can use it.
                bluetoothHeadsetStateReceiver = receiver;
            }
        }

        @Override
        protected void unregisterReceiver(BroadcastReceiver receiver) {
            Log.d(TAG, "unregisterReceiver");
            if (receiver == bluetoothHeadsetStateReceiver) {
                bluetoothHeadsetStateReceiver = null;
            }
        }

        @Override
        protected boolean getBluetoothProfileProxy(
                Context context, BluetoothProfile.ServiceListener listener, int profile) {
            Log.d(TAG, "getBluetoothProfileProxy");
            if (profile == BluetoothProfile.HEADSET) {
                // Allows the test to access the real Bluetooth service listener object.
                bluetoothServiceListener = listener;
            }
            return true;
        }

        @Override
        protected boolean hasPermission(Context context, String permission) {
            Log.d(TAG, "hasPermission(" + permission + ")");
            // Ensure that the client asks for Bluetooth permission.
            return (permission == android.Manifest.permission.BLUETOOTH);
        }

        @Override
        protected void logBluetoothAdapterInfo(BluetoothAdapter localAdapter) {
            // Do nothing in tests. No need to mock BluetoothAdapter.
        }
    };
}
 
開發者ID:lgyjg,項目名稱:AndroidRTC,代碼行數:63,代碼來源:BluetoothManagerTest.java

示例11: getProfileCode

@Override
public int getProfileCode() {
	return BluetoothProfile.HEADSET;
}
 
開發者ID:Joy-Whale,項目名稱:BluetoothProfile,代碼行數:4,代碼來源:BluetoothHeadsetProfile.java


注:本文中的android.bluetooth.BluetoothProfile.HEADSET屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。