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


Java BluetoothAdapter.STATE_CONNECTED屬性代碼示例

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


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

示例1: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    Log.i(TAG, "blueConnectStateBroadcastReceiver action>>>>" + intent.getAction());
    if (intent.getAction() == null)
        return;
    if (intent.getAction().equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
        int blueconState = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, 0);
        switch (blueconState) {
            case BluetoothAdapter.STATE_CONNECTED:
                Log.i(TAG, "blueConnectStateBroadcastReceiver>>>>STATE_CONNECTED");
                voiceMediator.setBlueHeadSet(true);
                isBlueToothHeadsetConnected();
                break;
            case BluetoothAdapter.STATE_CONNECTING:
                Log.i(TAG, "blueConnectStateBroadcastReceiver>>>>STATE_CONNECTING");
                break;
            case BluetoothAdapter.STATE_DISCONNECTED:
                Log.i(TAG, "blueConnectStateBroadcastReceiver>>>>STATE_DISCONNECTED");
                voiceMediator.setBlueHeadSet(false);
                voiceMediator.setSuportA2DP(false);
                AudioManager mAudioManager_ = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                mAudioManager_.setBluetoothScoOn(false);
                mAudioManager_.stopBluetoothSco();
                break;
            case BluetoothAdapter.STATE_DISCONNECTING:
                Log.i(TAG, "blueConnectStateBroadcastReceiver>>>>STATE_DISCONNECTING");
                voiceMediator.setSuportA2DP(false);
                break;
            default:
                break;
        }
    }
}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:33,代碼來源:AssistantService.java

示例2: onConnectionStateChanged

@Override
public void onConnectionStateChanged(Connection connection, int newState) {
    if (connectionStateListener != null) {
        connectionStateListener.onConnectionStateChanged(connection, newState);
    }

    if (newState == BluetoothAdapter.STATE_DISCONNECTED) {
        NeatleLogger.d("Will try to reconnect to " + connection.getDevice().getAddress() + " after " + (reconnectTimeout / 1000) + " seconds");

        handler.removeCallbacks(reconnectRunnable);
        handler.postDelayed(reconnectRunnable, reconnectTimeout);
        reconnectTimeout = Math.min(reconnectTimeout * 2, MAX_RECONNECT_TIMEOUT);
    } else if (newState == BluetoothAdapter.STATE_CONNECTED) {
        reconnectTimeout = DEFAULT_RECONNECT_TIMEOUT;
    }
}
 
開發者ID:inovait,項目名稱:neatle,代碼行數:16,代碼來源:ConnectionMonitorImpl.java

示例3: updateBtIconVisibility

private void updateBtIconVisibility() {
    if (mSbService == null || mBtMode == null) return;

    try {
        BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
        if (btAdapter != null) {
            boolean enabled = btAdapter.getState() == BluetoothAdapter.STATE_ON;
            boolean connected = (Integer) XposedHelpers.callMethod(btAdapter, "getConnectionState") ==
                    BluetoothAdapter.STATE_CONNECTED;
            boolean visible;
            switch (mBtMode) {
                default:
                case DEFAULT: visible = enabled; break;
                case CONNECTED: visible = connected; break;
                case HIDDEN: visible = false; break;
            }
            if (DEBUG) log("updateBtIconVisibility: enabled=" + enabled + "; connected=" + connected +
                    "; visible=" + visible);
            XposedHelpers.callMethod(mSbService, "setIconVisibility", "bluetooth", visible);
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:24,代碼來源:SystemIconController.java

示例4: isBTHeadsetConnected

@Override
public boolean isBTHeadsetConnected() {
    if(bluetoothAdapter != null) {
        return (bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET) == BluetoothAdapter.STATE_CONNECTED);
    }
    return false;
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:7,代碼來源:BluetoothUtils14.java

示例5: stateToString

/**
 * Converts BluetoothAdapter states into local string representations.
 */
private String stateToString(int state) {
    switch (state) {
        case BluetoothAdapter.STATE_DISCONNECTED:
            return "DISCONNECTED";
        case BluetoothAdapter.STATE_CONNECTED:
            return "CONNECTED";
        case BluetoothAdapter.STATE_CONNECTING:
            return "CONNECTING";
        case BluetoothAdapter.STATE_DISCONNECTING:
            return "DISCONNECTING";
        case BluetoothAdapter.STATE_OFF:
            return "OFF";
        case BluetoothAdapter.STATE_ON:
            return "ON";
        case BluetoothAdapter.STATE_TURNING_OFF:
            // Indicates the local Bluetooth adapter is turning off. Local clients should immediately
            // attempt graceful disconnection of any remote links.
            return "TURNING_OFF";
        case BluetoothAdapter.STATE_TURNING_ON:
            // Indicates the local Bluetooth adapter is turning on. However local clients should wait
            // for STATE_ON before attempting to use the adapter.
            return "TURNING_ON";
        default:
            return "INVALID";
    }
}
 
開發者ID:nhancv,項目名稱:nc-android-webrtcpeer,代碼行數:29,代碼來源:BluetoothManager.java

示例6: stateToString

/** Converts BluetoothAdapter states into local string representations. */
private String stateToString(int state) {
  switch (state) {
    case BluetoothAdapter.STATE_DISCONNECTED:
      return "DISCONNECTED";
    case BluetoothAdapter.STATE_CONNECTED:
      return "CONNECTED";
    case BluetoothAdapter.STATE_CONNECTING:
      return "CONNECTING";
    case BluetoothAdapter.STATE_DISCONNECTING:
      return "DISCONNECTING";
    case BluetoothAdapter.STATE_OFF:
      return "OFF";
    case BluetoothAdapter.STATE_ON:
      return "ON";
    case BluetoothAdapter.STATE_TURNING_OFF:
      // Indicates the local Bluetooth adapter is turning off. Local clients should immediately
      // attempt graceful disconnection of any remote links.
      return "TURNING_OFF";
    case BluetoothAdapter.STATE_TURNING_ON:
      // Indicates the local Bluetooth adapter is turning on. However local clients should wait
      // for STATE_ON before attempting to use the adapter.
      return  "TURNING_ON";
    default:
      return "INVALID";
  }
}
 
開發者ID:Piasy,項目名稱:AppRTC-Android,代碼行數:27,代碼來源:AppRTCBluetoothManager.java

示例7: onConnectionStateChanged

@Override
public void onConnectionStateChanged(Connection connection, int newState) {
    if (newState == BluetoothAdapter.STATE_CONNECTED) {
        subscribeOnDevice();
    }
}
 
開發者ID:inovait,項目名稱:neatle,代碼行數:6,代碼來源:CharacteristicSubscriptionImpl.java


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