本文整理汇总了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;
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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);
}
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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");
}
示例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();
}
}
示例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();
}
}
示例12: registerStateReciever
private void registerStateReciever(Context context) {
IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
context.registerReceiver(broadcastReceiver, intentFilter);
}