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


Java BluetoothProfile.STATE_CONNECTED屬性代碼示例

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


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

示例1: optional

private void optional() {
        HeadsetPlugManager.getInstance().registerHeadsetPlugListener(this);
        mHeadsetListener = new HeadsetBroadcastReceiver();
        registerReceiver(mHeadsetListener, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
        mBluetoothHeadsetBroadcastListener = new BluetoothHeadsetBroadcastReceiver();
        mBtAdapter = BluetoothAdapter.getDefaultAdapter();
        if (mBtAdapter != null && BluetoothProfile.STATE_CONNECTED == mBtAdapter.getProfileConnectionState(BluetoothProfile.HEADSET)) {
            // on some devices, BT is not supported
            boolean bt = mBtAdapter.getProfileProxy(getBaseContext(), mBluetoothHeadsetListener, BluetoothProfile.HEADSET);
            int connection = mBtAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
        }
        IntentFilter i = new IntentFilter(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
        i.addAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
        i.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
        registerReceiver(mBluetoothHeadsetBroadcastListener, i);
//避免對window添加ui修改參數
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

        setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
    }
 
開發者ID:wzc25151,項目名稱:lrs_android,代碼行數:21,代碼來源:AgoraActivity.java

示例2: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
	String intentAction;
	if (newState == BluetoothProfile.STATE_CONNECTED) {
		Log.i(TAG, "Connected to GATT server.");
		if( gatt.getDevice().getBondState() != BluetoothDevice.BOND_BONDED ) {
			broadcastUpdate(ACTION_NOT_PAIRED);
			gatt.disconnect();
			return;
		}
		Log.i(TAG, "Attempting to start service discovery" );
		mBluetoothGatt.discoverServices();
		connected = true;
		broadcastUpdate(ACTION_GATT_CLIENT_CONNECTED);
	}
	else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
		intentAction = ACTION_GATT_CLIENT_DISCONNECTED;
		Log.i(TAG, "Disconnected from GATT server.");
		broadcastUpdate(intentAction);
		connected = false;
	}
}
 
開發者ID:masterjc,項目名稱:bluewatcher,代碼行數:22,代碼來源:BluetoothClientService.java

示例3: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    super.onConnectionStateChange(gatt, status, newState);

    if (newState == BluetoothProfile.STATE_CONNECTED) {
        connected = true;
        gatt.discoverServices();
    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        connected = false;
        btGatt.close();
        btGatt = null;
        charSerial = null;
        messenger.obtainMessage(MessageConstants.STATUS, StatusCode.Disconnected).sendToTarget();
    } else {
        messenger.obtainMessage(MessageConstants.ERROR, ErrorCode.Connect).sendToTarget();
        taskConnectTimeout.cancel();
    }
}
 
開發者ID:e-regular-games,項目名稱:arduator,代碼行數:18,代碼來源:ArduinoCommBle.java

示例4: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        if(mOnConnectListener!=null)
            mOnConnectListener.onConnect(gatt);
        Log.i(TAG, "Connected to GATT server.");
        // Attempts to discover services after successful connection.
        Log.i(TAG, "Attempting to start service discovery:" +
                mBluetoothGatt.discoverServices());

    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        if(mOnDisconnectListener!=null)
            mOnDisconnectListener.onDisconnect(gatt);
        Log.i(TAG, "Disconnected from GATT server.");
    }

    if(mOnConnectStatusChangedListener!=null)
        mOnConnectStatusChangedListener.onConnectStatusChanged(gatt,status,newState);
        Log.i(TAG, "Changed");

}
 
開發者ID:haoyifan,項目名稱:BLE-PEPS,代碼行數:21,代碼來源:BluetoothLeClass.java

示例5: onConnectionStateChange

/**
 * Callback indicating when GATT client has connected/disconnected to/from a remote
 * GATT server.
 *
 * @param gatt     GATT client
 * @param status   Status of the connect or disconnect operation.
 *                 {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
 * @param newState Returns the new connection state. Can be one of
 *                 {@link android.bluetooth.BluetoothProfile#STATE_DISCONNECTED} or
 *                 {@link android.bluetooth.BluetoothProfile#STATE_CONNECTED}
 */
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    super.onConnectionStateChange(gatt, status, newState);

    // boolean indicating whether or not the next step is successful, default is false
    boolean success = false;

    // Start Service discovery if we're now connected
    if (status == BluetoothGatt.GATT_SUCCESS) {
        if (newState == BluetoothProfile.STATE_CONNECTED) {
            success = gatt.discoverServices();
        } // else: not connected, continue
    } // else: not successful

    onStep(gatt, success);
}
 
開發者ID:SPINremote,項目名稱:sdc-1-quickstart-android,代碼行數:27,代碼來源:MainActivity.java

示例6: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    Log.e(TAG, "onConnectionStateChanged");

    String intentAction;
    if (newState == BluetoothProfile.STATE_CONNECTED) { // STATE : connected
        intentAction = ACTION_GATT_CONNECTED;
        mConnectionState = STATE_CONNECTED;

        broadcastUpdate(intentAction); // broadcast Gatt connection state : connected

        Log.e(TAG, "Connected to GATT server.");
        Log.e(TAG, "Attempting to start service discovery:" + mBluetoothGatt.discoverServices());

    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { // STATE : disconnected
        intentAction = ACTION_GATT_DISCONNECTED;
        mConnectionState = STATE_DISCONNECTED;

        broadcastUpdate(intentAction); // broadcast Gatt connection state : disconnected

        Log.e(TAG, "Disconnected from GATT server.");
    }
}
 
開發者ID:skydoves,項目名稱:MagicLight-Controller,代碼行數:23,代碼來源:BluetoothLeService.java

示例7: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    String intentAction;
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        intentAction = ACTION_GATT_CONNECTED;
        mConnectionState = STATE_CONNECTED;
        broadcastUpdate(intentAction);
        Log.i(TAG, "Connected to GATT server.");
        // Attempts to discover services after successful connection.
        Log.i(TAG, "Attempting to start service discovery:" +
                mBluetoothGatt.discoverServices());

    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        intentAction = ACTION_GATT_DISCONNECTED;
        mConnectionState = STATE_DISCONNECTED;
        Log.i(TAG, "Disconnected from GATT server.");
        broadcastUpdate(intentAction);
    }
}
 
開發者ID:richhowley,項目名稱:Android-BLE-to-Arduino,代碼行數:19,代碼來源:BluetoothLeService.java

示例8: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    String intentAction;
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        intentAction = ACTION_GATT_CONNECTED;
        mConnectionState = STATE_CONNECTED;

        Log.i(TAG, "Connected to GATT server.");
        // Attempts to discover services after successful connection.
        Log.i(TAG, "Attempting to start service discovery:" +
                mBluetoothGatt.discoverServices());

    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        intentAction = ACTION_GATT_DISCONNECTED;
        mConnectionState = STATE_DISCONNECTED;
        Log.i(TAG, "Disconnected from GATT server.");

    }
}
 
開發者ID:hcmlab,項目名稱:ssj,代碼行數:19,代碼來源:BLESensorListener.java

示例9: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
{
    mGatt = gatt;

    switch(newState)
    {
        case BluetoothProfile.STATE_CONNECTED:
            Log.d(TAG, "Gatt state: connected");
            gatt.discoverServices();
            mDeviceConnected = true;
            if(mConnectionLatch != null)
            {
                mConnectionLatch.countDown();
            }
            break;
        default:
            Log.d(TAG, "Gatt state: not connected");
            mDeviceConnected = false;
            break;
    }
}
 
開發者ID:martykan,項目名稱:mibandGeocaching,代碼行數:22,代碼來源:BLECommunicationManager.java

示例10: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    Config.logi("BluetoothGatt connection State Changed: [" + status + "]" + newState);
    String intentAction;
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        intentAction = ACTION_GATT_CONNECTED;
        mConnectionState = STATE_CONNECTED;
        broadcastUpdate(intentAction, gatt.getDevice().getAddress());
        Log.i(TAG, "Connected to GATT server.");
        // Attempts to discover services after successful connection.
        Log.i(TAG, "Attempting to startScan findService discovery:" +
                gatt.discoverServices());

    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        intentAction = ACTION_GATT_DISCONNECTED;
        mConnectionState = STATE_DISCONNECTED;
        gatt.close();//make 133 not fire.
        Log.i(TAG, "Disconnected from GATT server.");
        broadcastUpdate(intentAction, gatt.getDevice().getAddress());
    }
}
 
開發者ID:Grasea,項目名稱:Grandroid2,代碼行數:21,代碼來源:BluetoothLeService.java

示例11: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    String intentAction;
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        intentAction = ACTION_GATT_CONNECTED;
        broadcastUpdate(intentAction);
        Log.i(TAG, "Connected to GATT server.");
        // Attempts to discover services after successful connection.
        Log.i(TAG, "Attempting to start service discovery:" +
                mBluetoothGatt.discoverServices());

    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        intentAction = ACTION_GATT_DISCONNECTED;
        Log.i(TAG, "Disconnected from GATT server.");
        broadcastUpdate(intentAction);
    }
}
 
開發者ID:nladuo,項目名稱:IoT-Firstep,代碼行數:17,代碼來源:BluetoothLeService.java

示例12: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    Log.d(TAG, "Connection State Change: " + status + " -> " + connectionState(newState));
    if (status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothProfile.STATE_CONNECTED) {
        /*
         * Once successfully connected, we must next discover all the services on the
         * device before we can read and write their characteristics.
         */
        gatt.discoverServices();
        mHandler.sendMessage(Message.obtain(null, MSG_PROGRESS, "Discovering Services..."));
    } else if (status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothProfile.STATE_DISCONNECTED) {
        /*
         * If at any point we disconnect, send a message to clear the weather values
         * out of the UI
         */
        mHandler.sendEmptyMessage(MSG_CLEAR);
    } else if (status != BluetoothGatt.GATT_SUCCESS) {
        /*
         * If there is a failure at any stage, simply disconnect
         */
        gatt.disconnect();
    }
}
 
開發者ID:ruipoliveira,項目名稱:livingCity-Android,代碼行數:23,代碼來源:MainActivity.java

示例13: onConnectionStateChange

@Override
     public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
if (mProvClientDev != null) {
	if (mProvClientDev.getPeerDevice() != null) {
		if (mProvClientDev.getPeerDevice().equals(device)) {
			String strAddr = device.getAddress();
			byte[] addr = stringToAddress(strAddr);
			
            if (newState == BluetoothProfile.STATE_CONNECTED) {
				if (mProvClientDev.getConnectionState() == PeerDevice.STATE_DISCONNECTED) {
					mProvClientDev.setPeerDevice(device);
					mProvClientDev.setConnectionState(PeerDevice.STATE_CONNECTED);
					if (D) {
	                	Log.i(TAG, "Connected to GATT Client.");
					}

					connectionChangedNative(addr, true, status);
				}

            } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                mProvClientDev.setConnectionState(PeerDevice.STATE_DISCONNECTED);
				if (D) {
                	Log.i(TAG, "Disconnected from GATT Client.");
				}

				advertiseStop();
				connectionChangedNative(addr, false, status);

				mGattServer.close();
            }
		}
	}
}
     }
 
開發者ID:blxble,項目名稱:mesh-core-on-android,代碼行數:34,代碼來源:JniCallbacks.java

示例14: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    Log.d(TAG, "BluetoothGattCallback.nConnectionStateChange: status=" + status + " newState=" + newState);
    updateLog("Bluetooth connection state change: status="+ status + " newState=" + newState);
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        gatt.discoverServices();
    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        if (gatt.getDevice().getAddress().equals(mOWDevice.deviceMacAddress.get())) {
            onOWStateChangedToDisconnected(gatt);
        }
        updateLog("--> Closed " + gatt.getDevice().getAddress());
        Log.d(TAG, "Disconnect:" + gatt.getDevice().getAddress());
    }
}
 
開發者ID:ponewheel,項目名稱:android-ponewheel,代碼行數:14,代碼來源:BluetoothUtilImpl.java

示例15: onConnectionStateChange

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    NLog.d("onConnectionStatusChange status " + status + ", newStatue " + newState);
    super.onConnectionStateChange(gatt, status, newState);
    watchDog.cancel();
    if ( watchDogAlreadyCalled )
    {
        return;
    }
    switch (newState)
    {
        case BluetoothProfile.STATE_CONNECTED:

            mBluetoothGatt = gatt;
            onBinded();
            NLog.d("Connected");
            mtuIndex = 0;
            mtu = mtuLIst[mtuIndex];
            boolean ret = gatt.requestMtu(mtu);
            NLog.d("mtu test result : " + ret);
            break;
        case BluetoothProfile.STATE_DISCONNECTED:
            NLog.d("Disconnected");
            if ( mConnectionThread == null )
            {
                NLog.d("Connect failed");
                responseMsg( new PenMsg( PenMsgType.PEN_CONNECTION_FAILURE) );
                onDisconnected();
            }
            else
            {
                mConnectionThread.stopRunning();
            }
            close();
            break;
    }
}
 
開發者ID:NeoSmartpen,項目名稱:AndroidSDK2.0,代碼行數:38,代碼來源:BTLEAdt.java


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