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


Java BluetoothAdapter.STATE_ON属性代码示例

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


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

示例1: sendFDroid

public void sendFDroid() {
    // If Bluetooth has not been enabled/turned on, then enabling device discoverability
    // will automatically enable Bluetooth.
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
        if (adapter.getState() != BluetoothAdapter.STATE_ON) {
            Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
            discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120);
            startActivityForResult(discoverBt, REQUEST_BLUETOOTH_ENABLE_FOR_SEND);
        } else {
            sendFDroidApk();
        }
    } else {
        new AlertDialog.Builder(this)
                .setTitle(R.string.bluetooth_unavailable)
                .setMessage(R.string.swap_cant_send_no_bluetooth)
                .setNegativeButton(
                        R.string.cancel,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) { }
                        }
                ).create().show();
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:25,代码来源:SwapWorkflowActivity.java

示例2: onReceive

@Override
public void onReceive(Context context, Intent intent) {
  final String action = intent.getAction();

  if (action != null && action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
    final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
            BluetoothAdapter.ERROR);
    boolean active = false;
    switch (state) {
      case BluetoothAdapter.STATE_OFF:
        active = false;
        break;
      case BluetoothAdapter.STATE_ON:
        active = true;
        break;
    }

    final WritableMap eventMap = new WritableNativeMap();
    eventMap.putString(EVENT_TYPE, "bluetooth");
    eventMap.putBoolean(EVENT_STATUS, active);
    getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(RN_CONNECTIVITY_STATUS_TOPIC, eventMap);
  }
}
 
开发者ID:nearit,项目名称:react-native-connectivity-status,代码行数:23,代码来源:RNConnectivityStatusModule.java

示例3: pause

private void pause() {
    handler.removeCallbacks(pauseCallback);
    handler.removeCallbacks(resumeCallback);

    if (!scanning) {
        NeatleLogger.i("called pause, but there is no scanning in progress");
        return;
    }

    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (doStarted) {
        doStarted = false;
        onStop(adapter);
    }


    if (scanInterval > 0 && adapter.getState() == BluetoothAdapter.STATE_ON) {
        NeatleLogger.i("scanning paused, will resume in " + scanInterval + " milliseconds");
        handler.postDelayed(resumeCallback, scanInterval);
    } else {
        NeatleLogger.i("no scan interval set or bluetooth off, stopping scanning");
    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:23,代码来源:BaseScanner.java

示例4: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (!action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
        return;
    }
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    int state = adapter.getState();
    if (state == BluetoothAdapter.STATE_ON) {
        NeatleLogger.i("BluetoothAdapter turned on");
        resume();
    } else {
        NeatleLogger.i("BluetoothAdapter state changed to " + state  +", turning off");
        pause();
    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:16,代码来源:BaseScanner.java

示例5: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
        int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                BluetoothAdapter.ERROR);
        if (DEBUG) log("Bluetooth state changed: state=" + state +
                "; mBluetoothEnableForTether=" + mBluetoothEnableForTether);
        switch (state) {
            case BluetoothAdapter.STATE_ON:
                registerServiceListener();
                break;
            case BluetoothAdapter.STATE_OFF:
            case BluetoothAdapter.ERROR:
                unregisterServiceListener();
                break;
            default:
                // ignore transition states
        }
    }
    refreshState();
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:21,代码来源:BluetoothTetheringTile.java

示例6: 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

示例7: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);

    switch (state) {
        case BluetoothAdapter.STATE_ON:
            startClient();
            break;
        case BluetoothAdapter.STATE_OFF:
            stopClient();
            break;
        default:
            // Do nothing
            break;
    }
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:16,代码来源:GattClient.java

示例8: checkState

public void checkState(){
	Log.d(LOG_TAG, "checkState");

	BluetoothAdapter adapter = getBluetoothAdapter();
	String state = "off";
	switch (adapter.getState()){
		case BluetoothAdapter.STATE_ON:
			state = "on";
			break;
		case BluetoothAdapter.STATE_OFF:
			state = "off";
	}

	WritableMap map = Arguments.createMap();
	map.putString("state", state);
	Log.d(LOG_TAG, "state:" + state);
	sendEvent("BleAdminDidUpdateState", map);
}
 
开发者ID:YbrainInc,项目名称:react-native-ble-quick-sdk,代码行数:18,代码来源:BleAdmin.java

示例9: handleUpdateState

@Override
public void handleUpdateState(Object state, Object arg) {
    mState.visible = true;
    mState.booleanValue = false;

    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

    int btState = adapter == null ? BluetoothAdapter.ERROR : adapter.getState();
    if (isInErrorState(btState)) {
        mState.label = mGbContext.getString(R.string.qs_tile_bt_tethering_error);
        mState.icon = mGbContext.getDrawable(R.drawable.ic_qs_bt_tethering_off);
    } else if (btState == BluetoothAdapter.STATE_TURNING_ON ||
            btState == BluetoothAdapter.STATE_TURNING_OFF) {
        mState.label = "---";
        mState.icon = mGbContext.getDrawable(R.drawable.ic_qs_bt_tethering_off);
    } else if (btState == BluetoothAdapter.STATE_ON && isTetheringOn()) {
        mState.label = mGbContext.getString(R.string.qs_tile_bt_tethering_on);
        mState.icon = mGbContext.getDrawable(R.drawable.ic_qs_bt_tethering_on);
        mState.booleanValue = true;
    } else {
        mState.label = mGbContext.getString(R.string.qs_tile_bt_tethering_off);
        mState.icon = mGbContext.getDrawable(R.drawable.ic_qs_bt_tethering_off);
    }

    super.handleUpdateState(state, arg);
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:26,代码来源:BluetoothTetheringTile.java

示例10: conditionalStart

private void conditionalStart() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter == null) {
        NeatleLogger.e("Bluetooth LE scan failed to start. No bluetooth adapter found");
        return;
    }
    int adapterState = adapter.getState();
    if (adapterState != BluetoothAdapter.STATE_ON) {
        NeatleLogger.e("Bluetooth off, will start scanning when it turns on.");
        pause();
        return;
    }

    onStart(adapter, scanMode);
    doStarted = true;
    if (scanDuration > 0) {
        handler.postDelayed(pauseCallback, scanDuration);
    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:19,代码来源:BaseScanner.java

示例11: onReceive

@Override
public void onReceive(Context context, Intent intent) {
	Log.d(LOG_TAG, "onReceive");
	final String action = intent.getAction();

	String stringState = "";
	if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
		final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
				BluetoothAdapter.ERROR);
		switch (state) {
			case BluetoothAdapter.STATE_OFF:
				stringState = "off";
				break;
			case BluetoothAdapter.STATE_TURNING_OFF:
				stringState = "turning_off";
				break;
			case BluetoothAdapter.STATE_ON:
				stringState = "on";
				break;
			case BluetoothAdapter.STATE_TURNING_ON:
				stringState = "turning_on";
				break;
		}
	}

	WritableMap map = Arguments.createMap();
	map.putString("state", stringState);
	Log.d(LOG_TAG, "state: " + stringState);
	sendEvent("BleManagerDidUpdateState", map);
}
 
开发者ID:lenglengiOS,项目名称:react-native-blue-manager,代码行数:30,代码来源:BleManager.java

示例12: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    Logger.getInstance().Debug(TAG, "_bluetoothChangedReceiver");

    final String action = intent.getAction();
    if (action == null) {
        Logger.getInstance().Error(TAG, "_bluetoothChangedReceiver action is null");
        return;
    }
    Logger.getInstance().Debug(TAG, String.format(Locale.getDefault(), "Action is %s", action));

    if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
        final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
        Logger.getInstance().Debug(TAG, String.format(Locale.getDefault(), "State is %d", state));

        switch (state) {
            case BluetoothAdapter.STATE_OFF:
                _bluetoothIsEnabled = false;
                if (_beaconManager.isBound(PositioningService.this)) {
                    _beaconManager.unbind(PositioningService.this);
                }
                break;

            case BluetoothAdapter.STATE_ON:
                _bluetoothIsEnabled = true;
                SetScanEnabled(_scanEnabled);
                break;

            default:
                break;
        }
    }

}
 
开发者ID:GuepardoApps,项目名称:LucaHome-AndroidApplication,代码行数:34,代码来源:PositioningService.java

示例13: 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

示例14: newStateDetected

private void newStateDetected(int state) {
    bluetoothState = state;
    switch (state) {
        case BluetoothAdapter.STATE_OFF:
            //Indicates the local Bluetooth adapter is off.
            break;

        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.
            break;

        case BluetoothAdapter.STATE_ON:
            //Indicates the local Bluetooth adapter is on, and ready for use.
            break;

        case BluetoothAdapter.STATE_TURNING_OFF:
            if (!Pandwarf.getInstance().isConnected()) {
                return;
            }
            killAllProcess(new GollumCallbackGetBoolean() {
                @Override
                public void done(boolean b) {
                    EventBus.getDefault().postSticky(new StateEvent(DISCONNECTED, ""));
                }
            });
            //Indicates the local Bluetooth adapter is turning off. Local clients should immediately attempt graceful disconnection of any remote links.
            break;
    }
}
 
开发者ID:GRnice,项目名称:PandwarfDefenderProject,代码行数:29,代码来源:Main2Activity.java

示例15: onReceive

@Override
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();
	if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)){
		if (isProtected()){
			BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
			if (device.getAddress().equals(mBTDevice.getAddress())){
				request(AntiTheftService.REQUEST_START_ALARM, null);
				if (!setSP.isAntiTheftOpenBTEnhancedMode()){
					request(AntiTheftService.REQUEST_STOP_PROTECT, null);
					request(AntiTheftService.REQUEST_SHOW_MSG, "已绑定蓝牙设备已断开连接,蓝牙防盗服务已自动关闭.");
					onProgress(AntiTheftService.MSG_REFESH_VIEWS, null);
				}
			}
		}
	}else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)){
		int currState = intent.getExtras().getInt(BluetoothAdapter.EXTRA_STATE);
		int previusState = intent.getExtras().getInt(BluetoothAdapter.EXTRA_PREVIOUS_STATE);
		if ((previusState == BluetoothAdapter.STATE_ON) && (currState == BluetoothAdapter.STATE_TURNING_OFF)){
			//蓝牙已被主动关闭
			if (setSP.isAntiTheftBTClosedAlarm()){
				request(AntiTheftService.REQUEST_START_ALARM, null);
			}
			request(AntiTheftService.REQUEST_STOP_PROTECT, null);
			request(AntiTheftService.REQUEST_SHOW_MSG,"蓝牙已被关闭,蓝牙防盗服务已自动关闭!");
			onProgress(AntiTheftService.MSG_REFESH_VIEWS, null);
		}
	}
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:29,代码来源:BTProtector.java


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