当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothProfile类代码示例

本文整理汇总了Java中android.bluetooth.BluetoothProfile的典型用法代码示例。如果您正苦于以下问题:Java BluetoothProfile类的具体用法?Java BluetoothProfile怎么用?Java BluetoothProfile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BluetoothProfile类属于android.bluetooth包,在下文中一共展示了BluetoothProfile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: optional

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
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,代码行数:22,代码来源:AgoraActivity.java

示例2: onConnectionStateChange

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
	String intentAction;
	if (newState == BluetoothProfile.STATE_CONNECTED) {
		intentAction = ACTION_CONNECTED;
		connectionState = STATE_CONNECTED;
		broadcastUpdate(intentAction);
		Log.i(TAG, "Connected to GATT server.");
		Log.i(TAG, "Attempting to start service discovery:" + bluetoothGatt.discoverServices());

	} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
		intentAction = ACTION_DISCONNECTED;
		connectionState = STATE_DISCONNECTED;
		Log.i(TAG, "Disconnected from GATT server.");
		broadcastUpdate(intentAction);
	}
}
 
开发者ID:Make-A-Pede,项目名称:Make-A-Pede-Android-App,代码行数:18,代码来源:BluetoothLeService.java

示例3: startBluetooth

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
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,代码行数:40,代码来源:BluetoothManager.java

示例4: stopBluetooth

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
public void stopBluetooth() {
	Log.w("[Bluetooth] Stopping...");
	isBluetoothConnected = false;
	
	disableBluetoothSCO();
	
	if (mBluetoothAdapter != null && mProfileListener != null && mBluetoothHeadset != null) {
		mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
		mProfileListener = null;
	}
	mBluetoothDevice = null;
	
	Log.w("[Bluetooth] Stopped!");
	
	if (LinphoneManager.isInstanciated()) {
		LinphoneManager.getInstance().routeAudioToReceiver();
	}
}
 
开发者ID:treasure-lau,项目名称:Linphone4Android,代码行数:19,代码来源:BluetoothManager.java

示例5: onConnectionStateChange

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    super.onConnectionStateChange(gatt, status, newState);

    Log.d("BLUETOOTH", "Estado de conexión bluetooth: " + (newState == BluetoothProfile.STATE_CONNECTED ? "Connected" : "Disconnected"));

    if(newState == BluetoothProfile.STATE_CONNECTED){
        //setState(State.CONNECTED);
        mBluetoothGatt.discoverServices();
    }
    else{
        //setState(State.IDDLE);
        //TODO Realizar todas las tareas necesarias cuando se desconecte la pulsera
        Log.d("BLUETOOTH", "Se ha desconectado el dispostivo bluetooth");
    }
}
 
开发者ID:TfgReconocimientoPulseras,项目名称:TrainAppTFG,代码行数:17,代码来源:BluetoothLeService.java

示例6: onConnectionStateChange

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
@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,代码行数:19,代码来源:ArduinoCommBle.java

示例7: stop

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
/**
 * Stops and closes all components related to Bluetooth audio.
 */
public void stop() {
    ThreadUtils.checkIsOnMainThread();
    Log.d(TAG, "stop: BT state=" + bluetoothState);
    if (bluetoothAdapter == null) {
        return;
    }
    // Stop BT SCO connection with remote device if needed.
    stopScoAudio();
    // Close down remaining BT resources.
    if (bluetoothState == State.UNINITIALIZED) {
        return;
    }
    unregisterReceiver(bluetoothHeadsetReceiver);
    cancelTimer();
    if (bluetoothHeadset != null) {
        bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset);
        bluetoothHeadset = null;
    }
    bluetoothAdapter = null;
    bluetoothDevice = null;
    bluetoothState = State.UNINITIALIZED;
    Log.d(TAG, "stop done: BT state=" + bluetoothState);
}
 
开发者ID:nhancv,项目名称:nc-android-webrtcpeer,代码行数:27,代码来源:BluetoothManager.java

示例8: optionalDestroy

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
private void optionalDestroy() {
    if (mBtAdapter != null) {
        mBtAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothProfile);
        mBluetoothProfile = null;
        mBtAdapter = null;
    }
    if (mBluetoothHeadsetBroadcastListener != null) {
        unregisterReceiver(mBluetoothHeadsetBroadcastListener);
        mBluetoothHeadsetBroadcastListener = null;
    }
    if (mHeadsetListener != null) {
        unregisterReceiver(mHeadsetListener);
        mHeadsetListener = null;
    }
    HeadsetPlugManager.getInstance().unregisterHeadsetPlugListener(this);
}
 
开发者ID:wzc25151,项目名称:lrs_android,代码行数:17,代码来源:AgoraActivity.java

示例9: onConnectionStateChange

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
@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,代码行数:22,代码来源:BluetoothLeClass.java

示例10: onConnectionStateChange

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
/**
 * 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,代码行数:28,代码来源:MainActivity.java

示例11: onCreate

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
/**
 * Make sure Bluetooth and health profile are available on the Android device.  Stop service
 * if they are not available.
 */
@Override
public void onCreate() {
    super.onCreate();
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
        // Bluetooth adapter isn't available.  The client of the service is supposed to
        // verify that it is available and activate before invoking this service.
        stopSelf();
        return;
    }
    if (!mBluetoothAdapter.getProfileProxy(this, mBluetoothServiceListener,
            BluetoothProfile.HEALTH)) {
        Toast.makeText(this, R.string.bluetooth_health_profile_not_available,
                Toast.LENGTH_LONG);
        stopSelf();
        return;
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:23,代码来源:BluetoothHDPService.java

示例12: onConnectionStateChange

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
@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:igrow-systems,项目名称:igrow-android,代码行数:20,代码来源:BluetoothLeService.java

示例13: stop

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
/** Stops and closes all components related to Bluetooth audio. */
public void stop() {
  ThreadUtils.checkIsOnMainThread();
  Log.d(TAG, "stop: BT state=" + bluetoothState);
  if (bluetoothAdapter == null) {
    return;
  }
  // Stop BT SCO connection with remote device if needed.
  stopScoAudio();
  // Close down remaining BT resources.
  if (bluetoothState == State.UNINITIALIZED) {
    return;
  }
  unregisterReceiver(bluetoothHeadsetReceiver);
  cancelTimer();
  if (bluetoothHeadset != null) {
    bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset);
    bluetoothHeadset = null;
  }
  bluetoothAdapter = null;
  bluetoothDevice = null;
  bluetoothState = State.UNINITIALIZED;
  Log.d(TAG, "stop done: BT state=" + bluetoothState);
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:25,代码来源:AppRTCBluetoothManager.java

示例14: stop

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
/**
 * Stops and closes all components related to Bluetooth audio.
 */
public void stop() {
    ThreadUtils.checkIsOnMainThread();
    unregisterReceiver(bluetoothHeadsetReceiver);
    Log.d(TAG, "stop: BT state=" + bluetoothState);
    if (bluetoothAdapter != null) {
        // Stop BT SCO connection with remote device if needed.
        stopScoAudio();
        // Close down remaining BT resources.
        if (bluetoothState != State.UNINITIALIZED) {
            cancelTimer();
            if (bluetoothHeadset != null) {
                bluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset);
                bluetoothHeadset = null;
            }
            bluetoothAdapter = null;
            bluetoothDevice = null;
            bluetoothState = State.UNINITIALIZED;
        }
    }
    Log.d(TAG, "stop done: BT state=" + bluetoothState);
}
 
开发者ID:lgyjg,项目名称:AndroidRTC,代码行数:25,代码来源:AppRTCBluetoothManager.java

示例15: onConnectionStateChange

import android.bluetooth.BluetoothProfile; //导入依赖的package包/类
@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,代码行数:23,代码来源:BluetoothClientService.java


注:本文中的android.bluetooth.BluetoothProfile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。