相关文章推荐

android.bluetooth.BluetoothAdapter.getProfileProxy()

Here are the examples of the java api android.bluetooth.BluetoothAdapter.getProfileProxy() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

10 Examples View Source File : MainActivity.java
License : Apache License 2.0
Project Creator : LiuJunb
How to convert Python List to JSON ...

/**
 * 开始连接蓝牙设备
private void contectBuleDevices() {
     * 使用A2DP协议连接设备
    mBluetoothAdapter.getProfileProxy(this, mProfileServiceListener, BluetoothProfile.A2DP);
View Source File : A2dpSinkActivity.java
License : Apache License 2.0
Project Creator : androidthings

/**
 * Initiate the A2DP sink.
private void initA2DPSink() {
    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
        Log.e(TAG, "Bluetooth adapter not available or not enabled.");
        return;
    setupBTProfiles();
    Log.d(TAG, "Set up Bluetooth Adapter name and profile");
    mBluetoothAdapter.setName(ADAPTER_FRIENDLY_NAME);
    mBluetoothAdapter.getProfileProxy(this, new BluetoothProfile.ServiceListener() {
        @Override
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            mA2DPSinkProxy = proxy;
            enableDiscoverable();
        @Override
        public void onServiceDisconnected(int profile) {
    }, A2dpSinkHelper.A2DP_SINK_PROFILE);
    configureButton();
View Source File : AppRTCBluetoothManager.java
License : ISC License
Project Creator : zxcpoiu

protected boolean getBluetoothProfileProxy(Context context, BluetoothProfile.ServiceListener listener, int profile) {
    return bluetoothAdapter.getProfileProxy(context, listener, profile);
View Source File : BluetoothTetheringTile.java
License : Apache License 2.0
Project Creator : WrBug

private void registerServiceListener() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null && adapter.getState() == BluetoothAdapter.STATE_ON && mBluetoothPan.get() == null) {
        adapter.getProfileProxy(mContext, mProfileServiceListener, BT_PROFILE_PAN);
        if (DEBUG)
            log("Service listener registered");
View Source File : AbstractScanner.java
License : Apache License 2.0
Project Creator : wandersnail

private void getSystemConnectedDevices(Context context, int profile) {
    bluetoothAdapter.getProfileProxy(context, new BluetoothProfile.ServiceListener() {
        @Override
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            if (proxy == null)
                return;
            proxyBluetoothProfiles.put(profile, proxy);
            synchronized (AbstractScanner.this) {
                if (!isScanning)
                    return;
            try {
                List<BluetoothDevice> devices = proxy.getConnectedDevices();
                for (BluetoothDevice device : devices) {
                    parseScanResult(device, true);
            } catch (Exception ignore) {
        @Override
        public void onServiceDisconnected(int profile) {
    }, profile);
View Source File : MainActivity.java
License : Apache License 2.0
Project Creator : ralismark

private void getProxy() {
    mBtAdapter.getProfileProxy(this, new BluetoothProfile.ServiceListener() {
        @Override
        @SuppressLint("NewApi")
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            if (profile == BluetoothProfile.INPUT_HOST) {
                info("Got HID device");
                mBtHidDevice = (BluetoothInputHost) proxy;
                BluetoothHidDeviceAppSdpSettings sdp = new BluetoothHidDeviceAppSdpSettings("BlueHID", "Android HID hackery", "Android", (byte) 0x00, descriptor);
                mBtHidDevice.registerApp(sdp, null, null, new BluetoothHidDeviceCallback() {
                    @Override
                    public void onGetReport(BluetoothDevice device, byte type, byte id, int bufferSize) {
                        Log.v(TAG, "onGetReport: device=" + device + " type=" + type + " id=" + id + " bufferSize=" + bufferSize);
                    @Override
                    public void onConnectionStateChanged(BluetoothDevice device, final int state) {
                        Log.v(TAG, "onConnectionStateChanged: device=" + device + " state=" + state);
                        if (device.equals(mBtDevice)) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    TextView status = findViewById(R.id.status);
                                    if (state == BluetoothProfile.STATE_DISCONNECTED) {
                                        status.setText(R.string.status_disconnected);
                                        mBtDevice = null;
                                    } else if (state == BluetoothProfile.STATE_CONNECTING) {
                                        status.setText(R.string.status_connecting);
                                    } else if (state == BluetoothProfile.STATE_CONNECTED) {
                                        status.setText(R.string.status_connected);
                                    } else if (state == BluetoothProfile.STATE_DISCONNECTING) {
                                        status.setText(R.string.status_disconnecting);
        @Override
        public void onServiceDisconnected(int profile) {
            if (profile == BluetoothProfile.INPUT_HOST) {
                info("Lost HID device");
    }, BluetoothProfile.INPUT_HOST);
View Source File : HidDeviceProfile.java
License : Apache License 2.0
Project Creator : ginkage

/**
 * Initiate the connection to the profile proxy service.
 * @param context Context that is required to establish the service connection.
 * @param listener Callback that will receive the profile proxy object.
@MainThread
void registerServiceListener(Context context, ServiceStateListener listener) {
    context = checkNotNull(context).getApplicationContext();
    serviceStateListener = checkNotNull(listener);
    bluetoothAdapter.getProfileProxy(context, new ServiceListener(), BluetoothProfile.HID_DEVICE);
View Source File : BtManager.java
License : Apache License 2.0
Project Creator : ApolloAuto

public void prepareToPairMd(String remoteBTAddress) {
    this.mRemoteBTAddress = remoteBTAddress;
    if (!checkBTAvailable()) {
        openBluetooth();
    int connectionState = mBluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
    LogUtil.i(TAG, "connectionState=" + connectionState);
    switch(connectionState) {
        case BluetoothProfile.STATE_DISCONNECTED:
            Message msg = new Message();
            msg.what = BLUETOOTH_READY;
            mHandler.sendMessage(msg);
            break;
        case BluetoothProfile.STATE_CONNECTED:
            break;
        case BluetoothProfile.STATE_CONNECTING:
        case BluetoothProfile.STATE_DISCONNECTING:
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Message msg = new Message();
                    msg.what = BLUETOOTH_IS_CONNECTING;
                    mHandler.sendMessage(msg);
            }, 2000);
            break;
        default:
            break;
    mBluetoothAdapter.getProfileProxy(mContext, btProfileListener, BluetoothProfile.HEADSET);
View Source File : BluetoothHeadsetUtils.java
License : Apache License 2.0
Project Creator : niedev

/**
 * Register a headset profile listener
 * @return false    if device does not support bluetooth or current platform does not supports
 * use of SCO for off call or error in getting profile proxy.
private boolean startBluetooth11() {
    // //d(TAG, "startBluetooth11"); //$NON-NLS-1$
    // Device support bluetooth
    if (mBluetoothAdapter != null) {
        if (mAudioManager.isBluetoothScoAvailableOffCall()) {
            // All the detection and audio connection are done in mHeadsetProfileListener
            return mBluetoothAdapter.getProfileProxy(mContext, mHeadsetProfileListener, BluetoothProfile.HEADSET);
    return false;
View Source File : BluetoothUtils.java
License : GNU General Public License v3.0
Project Creator : bidmachine

public static void register(@Nullable Context context) {
    if (context == null || context.getApplicationContext() == null) {
        return;
    if (isRegistered) {
        return;
    if (!Utils.isPermissionGranted(context, Manifest.permission.BLUETOOTH)) {
        return;
    try {
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (bluetoothAdapter == null) {
            return;
        for (int profile : profileArray) {
            bluetoothAdapter.getProfileProxy(context.getApplicationContext(), listener, profile);
    } catch (Exception ignore) {
    isRegistered = true;
Categories
 
推荐文章