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


Java BluetoothAdapter.ACTION_STATE_CHANGED属性代码示例

本文整理汇总了Java中android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED属性的典型用法代码示例。如果您正苦于以下问题:Java BluetoothAdapter.ACTION_STATE_CHANGED属性的具体用法?Java BluetoothAdapter.ACTION_STATE_CHANGED怎么用?Java BluetoothAdapter.ACTION_STATE_CHANGED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.bluetooth.BluetoothAdapter的用法示例。


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

示例1: BluetoothControl20

public BluetoothControl20() {
	// cache adaptor
	mAdapter = BluetoothAdapter.getDefaultAdapter();

	if (mAdapter == null) throw new UnsupportedOperationException("No default bluetooth adapter");
	
	// initialize state
 BLUETOOTH_STATE_UNKNOWN = -1;
 BLUETOOTH_STATE_OFF = BluetoothAdapter.STATE_OFF;
 BLUETOOTH_STATE_TURNING_ON = BluetoothAdapter.STATE_TURNING_ON;
 BLUETOOTH_STATE_ON = BluetoothAdapter.STATE_ON;
 BLUETOOTH_STATE_TURNING_OFF = BluetoothAdapter.STATE_TURNING_OFF;
 
 BLUETOOTH_ACTION_STATE_CHANGED = BluetoothAdapter.ACTION_STATE_CHANGED;
 BLUETOOTH_EXTRA_STATE = BluetoothAdapter.EXTRA_STATE;
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:16,代码来源:BluetoothSettingHandler.java

示例2: onCreate

public void onCreate(Context context, GattServerListener listener) throws RuntimeException {
    mContext = context;
    mListener = listener;

    mBluetoothManager = (BluetoothManager) context.getSystemService(BLUETOOTH_SERVICE);
    BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
    if (!checkBluetoothSupport(bluetoothAdapter)) {
        throw new RuntimeException("GATT server requires Bluetooth support");
    }

    // Register for system Bluetooth events
    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    mContext.registerReceiver(mBluetoothReceiver, filter);
    if (!bluetoothAdapter.isEnabled()) {
        Log.d(TAG, "Bluetooth is currently disabled... enabling");
        bluetoothAdapter.enable();
    } else {
        Log.d(TAG, "Bluetooth enabled... starting services");
        startAdvertising();
        startServer();
    }
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:22,代码来源:GattServer.java

示例3: onCreate

public void onCreate(Context context, String deviceAddress, OnCounterReadListener listener) throws RuntimeException {
    mContext = context;
    mListener = listener;
    mDeviceAddress = deviceAddress;

    mBluetoothManager = (BluetoothManager) context.getSystemService(BLUETOOTH_SERVICE);
    mBluetoothAdapter = mBluetoothManager.getAdapter();
    if (!checkBluetoothSupport(mBluetoothAdapter)) {
        throw new RuntimeException("GATT client requires Bluetooth support");
    }

    // Register for system Bluetooth events
    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    mContext.registerReceiver(mBluetoothReceiver, filter);
    if (!mBluetoothAdapter.isEnabled()) {
        Log.w(TAG, "Bluetooth is currently disabled... enabling");
        mBluetoothAdapter.enable();
    } else {
        Log.i(TAG, "Bluetooth enabled... starting client");
        startClient();
    }
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:22,代码来源:GattClient.java

示例4: InitBleAdmin

private void InitBleAdmin()
{
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
		settings = new ScanSettings.Builder()
				.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
				.build();
	}

	IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
	//context.registerReceiver(mReceiver, filter);
	this.reactContext.registerReceiver(mReceiver, filter);



	//didBleAdminLoad();
}
 
开发者ID:YbrainInc,项目名称:react-native-ble-quick-sdk,代码行数:16,代码来源:BleAdmin.java

示例5: addStateListener

private void addStateListener() {
    if (this.stateReceiver == null) {
        this.stateReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                onBluetoothStateChange(intent);
            }
        };
    }

    try {
        IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
        webView.getContext().registerReceiver(this.stateReceiver, intentFilter);
    } catch (Exception e) {
        LOG.e(TAG, "Error registering state receiver: " + e.getMessage(), e);
    }
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:17,代码来源:BLECentralPlugin.java

示例6: onCreate

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mSettings = new Settings(this);

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, R.string.bluetooth_not_available, Toast.LENGTH_LONG).show();
        this.finish();
        return;
    }

    IntentFilter disconnectFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    this.registerReceiver(mReceiver, disconnectFilter);

    setContentView(R.layout.activity_bluetooth_connector);
}
 
开发者ID:FelixWohlfrom,项目名称:Presenter-Client-Android,代码行数:21,代码来源:BluetoothConnector.java

示例7: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case BluetoothAdapter.ACTION_STATE_CHANGED:
            int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
            switch (state) {
                case BluetoothAdapter.STATE_TURNING_ON:// 蓝牙打开中

                    break;
                case BluetoothAdapter.STATE_ON:// 蓝牙打开完成

                    break;
                case BluetoothAdapter.STATE_TURNING_OFF:// 蓝牙关闭中

                    break;
                case BluetoothAdapter.STATE_OFF:// 蓝牙关闭完成

                    break;
                default:
                    break;
            }
        default:
            break;
    }
}
 
开发者ID:RockyQu,项目名称:BluetoothKit,代码行数:25,代码来源:BluetoothReceiver.java

示例8: onReceive

/**
 * {@inheritDoc}
 */
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Log.d(TAG, "Incoming intent : " + action);
    switch (action) {
        case BluetoothDevice.ACTION_FOUND :
            // Discovery has found a device. Get the BluetoothDevice
            // object and its info from the Intent.
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            Log.d(TAG, "Device discovered! " + BluetoothController.deviceToString(device));
            listener.onDeviceDiscovered(device);
            break;
        case BluetoothAdapter.ACTION_DISCOVERY_FINISHED :
            // Discovery has ended.
            Log.d(TAG, "Discovery ended.");
            listener.onDeviceDiscoveryEnd();
            break;
        case BluetoothAdapter.ACTION_STATE_CHANGED :
            // Discovery state changed.
            Log.d(TAG, "Bluetooth state changed.");
            listener.onBluetoothStatusChanged();
            break;
        case BluetoothDevice.ACTION_BOND_STATE_CHANGED :
            // Pairing state has changed.
            Log.d(TAG, "Bluetooth bonding state changed.");
            listener.onDevicePairingEnded();
            break;
        default :
            // Does nothing.
            break;
    }
}
 
开发者ID:aurasphere,项目名称:blue-pair,代码行数:35,代码来源:BroadcastReceiverDelegator.java

示例9: start

@ReactMethod
public void start(ReadableMap options, Callback callback) {
	Log.d(LOG_TAG, "start");
	boolean restart = false;
	if (options!=null&&options.hasKey("restart")) {
		restart = options.getBoolean("restart");
		if(restart){
			Log.d(LOG_TAG, "restart");
			bluetoothAdapter=null;
			scanManager=null;
               try {
                   context.unregisterReceiver(mReceiver);
               }catch (Exception e){}
		}
	}
	if (getBluetoothAdapter() == null) {
		Log.d(LOG_TAG, "No bluetooth support");
		callback.invoke("No bluetooth support");
		return;
	}
       Log.d(LOG_TAG, "options "+options.toString());
	boolean forceLegacy = true;
	if (options!=null&&options.hasKey("forceLegacy")) {
		forceLegacy = options.getBoolean("forceLegacy");
	}

	if (Build.VERSION.SDK_INT >= LOLLIPOP && !forceLegacy) {
           Log.d(LOG_TAG, "LollipopScanManager");
		scanManager = new LollipopScanManager(reactContext, context,this);
	} else {
		Log.d(LOG_TAG, "LegacyScanManager");
		scanManager = new LegacyScanManager(reactContext, context,this);
	}
	IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
	context.registerReceiver(mReceiver, filter);
	callback.invoke();
	Log.d(LOG_TAG, "BleManager initialized");
}
 
开发者ID:lenglengiOS,项目名称:react-native-blue-manager,代码行数:38,代码来源:BleManager.java

示例10: onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_server);

    mLocalTimeView = (TextView) findViewById(R.id.text_time);

    // Devices with a display should not go to sleep
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    mBluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
    BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
    // We can't continue without proper Bluetooth support
    if (!checkBluetoothSupport(bluetoothAdapter)) {
        finish();
    }

    // Register for system Bluetooth events
    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    registerReceiver(mBluetoothReceiver, filter);
    if (!bluetoothAdapter.isEnabled()) {
        Log.d(TAG, "Bluetooth is currently disabled...enabling");
        bluetoothAdapter.enable();
    } else {
        Log.d(TAG, "Bluetooth enabled...starting services");
        startAdvertising();
        startServer();
    }
}
 
开发者ID:androidthings,项目名称:sample-bluetooth-le-gattserver,代码行数:29,代码来源:GattServerActivity.java

示例11: start

public void start() {
    Log.i(TAG, "Server starting...");
    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    context.registerReceiver(this, filter);

    SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    defaultSharedPreferences.registerOnSharedPreferenceChangeListener(this);

    boolean mustRun = defaultSharedPreferences.getBoolean("main_enable_switch", true);

    if (mustRun) {
        startAll();
    }
}
 
开发者ID:RomascuAndrei,项目名称:BTNotifierAndroid,代码行数:14,代码来源:Server.java

示例12: registerStateReciever

private void registerStateReciever(Context context) {
    IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    context.registerReceiver(broadcastReceiver, intentFilter);
}
 
开发者ID:inovait,项目名称:neatle,代码行数:4,代码来源:BaseScanner.java


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