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


Java BluetoothAdapter.getState方法代码示例

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


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

示例1: sendFDroid

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
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,代码行数:26,代码来源:SwapWorkflowActivity.java

示例2: checkState

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@ReactMethod
public void checkState(){
	Log.d(LOG_TAG, "checkState");

	BluetoothAdapter adapter = getBluetoothAdapter();
	String state = "off";
	if (adapter != null) {
		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("BleManagerDidUpdateState", map);
}
 
开发者ID:lenglengiOS,项目名称:react-native-blue-manager,代码行数:22,代码来源:BleManager.java

示例3: checkState

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

示例4: conditionalStart

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
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,代码行数:20,代码来源:BaseScanner.java

示例5: pause

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
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,代码行数:24,代码来源:BaseScanner.java

示例6: onReceive

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

示例7: updateBtIconVisibility

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
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,代码行数:25,代码来源:SystemIconController.java

示例8: handleUpdateState

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

示例9: handleClick

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
public void handleClick() {
    if (mBluetoothEnableForTether)
        return;

    if (isTetheringOn()) {
        setTethering(false);
    } else {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (adapter != null) {
            if (adapter.getState() == BluetoothAdapter.STATE_OFF) {
                mBluetoothEnableForTether = true;
                adapter.enable();
            } else if (adapter.getState() == BluetoothAdapter.STATE_ON) {
                setTethering(true);
            }
        }
    }
    refreshState();
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:21,代码来源:BluetoothTetheringTile.java

示例10: getBluetoothState

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
 * 获取蓝牙的状态
 *
 * @return 取值为BluetoothAdapter的四个静态字段:STATE_OFF, STATE_TURNING_OFF,
 * STATE_ON, STATE_TURNING_ON
 * @throws Exception 没有找到蓝牙设备
 */
public static int getBluetoothState() throws Exception {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter == null) {
        throw new Exception("bluetooth device not found!");
    } else {
        return bluetoothAdapter.getState();
    }
}
 
开发者ID:RockyQu,项目名称:MVVMFrames,代码行数:16,代码来源:DeviceUtils.java

示例11: registerServiceListener

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
private void registerServiceListener() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null && adapter.getState() == BluetoothAdapter.STATE_ON &&
            mBluetoothPan.get() == null) {
        adapter.getProfileProxy(mContext, mProfileServiceListener,
                BT_PROFILE_PAN);
        if (DEBUG) log("Service listener registered");
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:10,代码来源:BluetoothTetheringTile.java


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