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


Java BluetoothAdapter.enable方法代码示例

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


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

示例1: onCreate

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intro);
        ButterKnife.bind(this);

        // set a default name
        username = Build.MODEL.split(" ")[0].length() >= 7 ?
                Build.MODEL.split(" ")[0] : Build.MODEL.replaceAll("\\s","");
        txtUsername.setText(username);;

//        // Configure the Toolbar
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.setTitle(getTitle());

        // Enabling bluetooth automatically
        if (isThingsDevice(this)) {
            BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            bluetoothAdapter.enable();
        }
    }
 
开发者ID:bridgefy,项目名称:bridgefy-android-samples,代码行数:23,代码来源:IntroActivity.java

示例2: SetNewBluetoothState

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public void SetNewBluetoothState(boolean isEnabled) {
    Logger.getInstance().Debug(TAG, String.format(Locale.getDefault(), "SetNewBluetoothState: %s", isEnabled));
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (isEnabled) {
        if (IsBluetoothEnabled()) {
            Logger.getInstance().Information(TAG, "BT already enabled!");
            return;
        }
        bluetoothAdapter.enable();
    } else {
        if (!IsBluetoothEnabled()) {
            Logger.getInstance().Information(TAG, "BT already disabled!");
            return;
        }
        bluetoothAdapter.disable();
    }
}
 
开发者ID:GuepardoApps,项目名称:LucaHome-AndroidApplication,代码行数:18,代码来源:BluetoothController.java

示例3: checkBluetooth

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
static public boolean checkBluetooth(Context context){
    BluetoothManager bm = (BluetoothManager) context.getSystemService(BLUETOOTH_SERVICE);
    BluetoothAdapter ba = bm.getAdapter();
    if (ba == null) {
        //Bluetooth is disabled
        Log.e(TAG, "BluetoothAdapter not available!");
        return false;
    }

    if(!ba.isEnabled()) {
        Log.w(TAG, "BluetoothAdapter not enabled!");
        ba.enable();
    }

    if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        Log.e(TAG, "Bluetooth LE is not supported");
        return false;
    }

    if(!ba.isMultipleAdvertisementSupported()){
        Log.i(TAG, "No Multiple Advertisement Support!");
    }

    return ba.isEnabled();
}
 
开发者ID:holgi-s,项目名称:RangeThings,代码行数:26,代码来源:GattServer.java

示例4: onCreate

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

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

示例6: setBluetooth

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public void setBluetooth(Context context, int resId) {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter == null) {
        displayNotification(context, "Unable to get BluetoothAdapter");
        return;
    }


    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String value = prefs.getString(context.getString(resId), "unset");
    if (value.equalsIgnoreCase("Enable")) {
        Log.i("StartBluetooth", "enabling bluetooth");
        bluetoothAdapter.enable();
    } else if (value.equalsIgnoreCase("Disable")) {
        Log.i("StartBluetooth", "disabling bluetooth");
        bluetoothAdapter.disable();
    }

}
 
开发者ID:Eun,项目名称:StartBluetooth,代码行数:20,代码来源:Service.java

示例7: onCreate

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Configure the Toolbar
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle(getTitle());

    RecyclerView recyclerView = findViewById(R.id.peer_list);
    recyclerView.setAdapter(peersAdapter);



    if (isThingsDevice(this)) {
        //enabling bluetooth automatically
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        bluetoothAdapter.enable();
    }

    Bridgefy.initialize(getApplicationContext(), new RegistrationListener() {
        @Override
        public void onRegistrationSuccessful(BridgefyClient bridgefyClient) {
            // Start Bridgefy
            startBridgefy();
        }

        @Override
        public void onRegistrationFailed(int errorCode, String message) {
            Toast.makeText(getBaseContext(), getString(R.string.registration_error),
                    Toast.LENGTH_LONG).show();
        }
    });
}
 
开发者ID:bridgefy,项目名称:bridgefy-android-samples,代码行数:36,代码来源:MainActivity.java

示例8: onCreate

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    setSupportActionBar(toolbar);

    // load our username
    username = getSharedPreferences(Constants.PREFS_NAME, 0).getString(Constants.PREFS_USERNAME, null);

    if (BridgefyListener.isThingsDevice(this)) {
        //if this device is running Android Things, don't go through any UI interaction and
        //start right away
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        //enabling bluetooth automatically
        bluetoothAdapter.enable();

        username = Build.MANUFACTURER + " " + Build.MODEL;
        // initialize the Bridgefy framework
        Bridgefy.initialize(getBaseContext(), registrationListener);
        setupList();

    } else {
        // check that we have permissions, otherwise fire the IntroActivity
        if ((ContextCompat.checkSelfPermission(getApplicationContext(),
                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
                (username == null)) {
            startActivity(new Intent(getBaseContext(), IntroActivity.class));
            finish();
        } else {
            // initialize the Bridgefy framework
            Bridgefy.initialize(getBaseContext(), registrationListener);
            setupList();
        }
    }
}
 
开发者ID:bridgefy,项目名称:bridgefy-android-samples,代码行数:37,代码来源:MainActivity.java

示例9: enableBluetooth

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
 * Turn on the bluetooth if it is not already turned on.
 */
private void enableBluetooth() {
    BluetoothAdapter adapter = ((BluetoothManager) mContext
            .getSystemService(Context.BLUETOOTH_SERVICE))
            .getAdapter();
    if (!adapter.isEnabled()) adapter.enable();
}
 
开发者ID:kevalpatel2106,项目名称:robo-car,代码行数:10,代码来源:Beacon.java

示例10: changeBluetoothState

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
private static void changeBluetoothState(Intent intent) {
    try {
        BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
        int labelResId;
        if (intent.hasExtra(AShortcut.EXTRA_ENABLE)) {
            if (intent.getBooleanExtra(AShortcut.EXTRA_ENABLE, false)) {
                btAdapter.enable();
                labelResId = R.string.bluetooth_on;
            } else {
                btAdapter.disable();
                labelResId = R.string.bluetooth_off;
            }
        } else {
            if (btAdapter.isEnabled()) {
                labelResId = R.string.bluetooth_off;
                btAdapter.disable();
            } else {
                btAdapter.enable();
                labelResId = R.string.bluetooth_on;
            }
        }
        if (intent.getBooleanExtra(AShortcut.EXTRA_SHOW_TOAST, false)) {
            Utils.postToast(mContext, labelResId);
        }
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:29,代码来源:ConnectivityServiceWrapper.java

示例11: onCreate

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

示例12: setBluetooth

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public static boolean setBluetooth(boolean enable) {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    boolean isEnabled = bluetoothAdapter.isEnabled();
    if (enable && !isEnabled) {
        isBluetoothOn = true;
        return bluetoothAdapter.enable();
    }
    else if(!enable && isEnabled) {
        isBluetoothOn = false;
        return bluetoothAdapter.disable();
    }
    // No need to change bluetooth state
    return true;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:15,代码来源:Utilities.java

示例13: OpenBluetoothModule

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
private boolean OpenBluetoothModule(){
    boolean bEnable = false;
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter != null){
        if (!(bEnable = bluetoothAdapter.isEnabled())) {
            bEnable = bluetoothAdapter.enable();
        }
    }
    return bEnable;
}
 
开发者ID:blxble,项目名称:mesh-core-on-android,代码行数:11,代码来源:MainActivity.java

示例14: onCreate

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    unbinder = ButterKnife.bind(this);

    deviceText.setText(Build.MANUFACTURER + " " + Build.MODEL);



    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();


    if (isThingsDevice(this))
    {
        //enabling bluetooth automatically
        bluetoothAdapter.enable();
    }

    Bridgefy.initialize(getApplicationContext(), "68898033-3dce-4c80-843e-e10982b942ac", new RegistrationListener() {
        @Override
        public void onRegistrationSuccessful(BridgefyClient bridgefyClient) {
            super.onRegistrationSuccessful(bridgefyClient);

            //Important data can be fetched from the BridgefyClient object
            deviceId.setText(bridgefyClient.getUserUuid());

            //Once the registration process has been successful, we can start operations
            Bridgefy.start(messageListener, stateListener);
        }

        @Override
        public void onRegistrationFailed(int i, String s) {
            super.onRegistrationFailed(i, s);
        }
    });


    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
}
 
开发者ID:bridgefy,项目名称:bridgefy-android-samples,代码行数:42,代码来源:MainActivity.java

示例15: initializeBridgefy

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
private void initializeBridgefy() {


        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();


        if (isThingsDevice(this))
        {
            //enabling bluetooth automatically
            bluetoothAdapter.enable();
        }
        //Always use steady context objects to avoid leaks
        Bridgefy.initialize(getApplicationContext(), registrationListener);

    }
 
开发者ID:bridgefy,项目名称:bridgefy-android-samples,代码行数:16,代码来源:DevicesActivity.java


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