當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothAdapter.ACTION_REQUEST_ENABLE屬性代碼示例

本文整理匯總了Java中android.bluetooth.BluetoothAdapter.ACTION_REQUEST_ENABLE屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothAdapter.ACTION_REQUEST_ENABLE屬性的具體用法?Java BluetoothAdapter.ACTION_REQUEST_ENABLE怎麽用?Java BluetoothAdapter.ACTION_REQUEST_ENABLE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.bluetooth.BluetoothAdapter的用法示例。


在下文中一共展示了BluetoothAdapter.ACTION_REQUEST_ENABLE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bluetooth);
    listView = (ListView) findViewById(R.id.listview);
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    registerReceiver(mReceiver, filter);
    mArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1);
    listView.setAdapter(mArrayAdapter);
    //1.獲取BluetoothAdapter;
    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter != null) {
        //2.啟用藍牙
        if (!bluetoothAdapter.isEnabled()) {
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
        } else {
            //查詢配對信息
            findDevice();
            discoverable();
        }
    } else {
        // 不支持藍牙
        Toast.makeText(this, "不支持藍牙設備", Toast.LENGTH_LONG).show();
    }
}
 
開發者ID:wuhighway,項目名稱:DailyStudy,代碼行數:26,代碼來源:BluetoothActivity.java

示例2: onResume

@Override
public void onResume() {
    super.onResume();

    // Register ChipRobotFinder broadcast receiver
    this.getActivity().registerReceiver(mChipFinderBroadcastReceiver, ChipRobotFinder.getChipRobotFinderIntentFilter());

    // Ensures Bluetooth is enabled on the device.  If Bluetooth is not currently enabled,
    // fire an intent to display a dialog asking the user to grant permission to enable it.
    if (mBluetoothAdapter != null && !mBluetoothAdapter.isEnabled()) {
        if (!mBluetoothAdapter.isEnabled()) {
            try {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);

            } catch (ActivityNotFoundException ex) {
            }
        }
    }

    // Start scan
    ChipRobotFinder.getInstance().clearFoundChipList();
    scanLeDevice(false);
    updateChipList();
    scanLeDevice(true);
}
 
開發者ID:WowWeeLabs,項目名稱:CHIP-Android-SDK,代碼行數:26,代碼來源:ConnectFragment.java

示例3: startBluetoothServices

/**
 * Starts bluetooth and listens to pairing requests and bluetooth state changes
 */
public static void startBluetoothServices() {
    mReceiver = new BluetoothReceiver();
    //Register the BroadcastReceiver for multiple bluetooth actions

    //when another bluetooth device is discovered in range
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

    //when discovering action finishes (discovering means that bluetooth searches for nearby devices)
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    //when bluetooth changes from on to off
    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);

    //when another device requests pairing with this device
    filter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST);

    mainActivity.mainRegisterReceiver(mReceiver, filter);

    if(!started) {
        //tries to start bluetooth if it is not on
       mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if(mBluetoothAdapter!=null){
            if (!mBluetoothAdapter.isEnabled()) {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                mainActivity.startActivityForResult(enableBtIntent, MainActivity.BLUETOOTH_ON);
            } else {
                started = true;
            }
        }

    }
}
 
開發者ID:mcr222,項目名稱:pass_the_bomb,代碼行數:34,代碼來源:BluetoothServices.java

示例4: enableBluetooth

@ReactMethod
public void enableBluetooth(Callback callback) {
	if (getBluetoothAdapter() == null) {
		Log.d(LOG_TAG, "No bluetooth support");
		callback.invoke("No bluetooth support");
		return;
	}
	if (!getBluetoothAdapter().isEnabled()) {
		enableBluetoothCallback = callback;
		Intent intentEnable = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
		if (getCurrentActivity() == null)
			callback.invoke("Current activity not available");
		else
			getCurrentActivity().startActivityForResult(intentEnable, ENABLE_REQUEST);
	} else
		callback.invoke();
}
 
開發者ID:lenglengiOS,項目名稱:react-native-blue-manager,代碼行數:17,代碼來源:BleManager.java

示例5: openBtDevice

private boolean openBtDevice() {
        // 獲得藍牙匹配器
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        // 藍牙設備不被支持
        if (mBluetoothAdapter == null) {
            Toast.makeText(getActivity(), "該設備沒有藍牙設備", Toast.LENGTH_LONG).show();
            return false;
        }

        // 藍牙如果沒打開,直接提示需要打開藍牙
        if (!mBluetoothAdapter.isEnabled()) {
            // 隱式Intent
            Intent enableBtIntent = new Intent(
                    BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBtIntent, REQUES_BT_ENABLE_CODE);  //在onActivityResult有打開服務端線程的操作哦
        } else {
            // 如果藍牙在運行本程序前已經人為打開,那麽直接啟動服務器端線程
            Toast.makeText(getActivity(), "藍牙已經打開!	", Toast.LENGTH_LONG).show();
            //暫時不啟動服務端線程,因為手機充當的總是客服端
//            mAcceptThread = new AcceptThread(mBluetoothAdapter,mHandler); // // // // // // // // // // // // // // // // // // // // // // // // //
//            mAcceptThread.start(); // // // // // // // // // // // // // // // //藍牙提前打開就啟動服務端線程? // // // // // //
        }
        return true;
    }
 
開發者ID:fergus825,項目名稱:SmartOrnament,代碼行數:24,代碼來源:LinkDeviceFragment.java

示例6: onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_bluetoothlist);
    this.setFinishOnTouchOutside(false);
    ButterKnife.bind(this);

    mHandler = new Handler();

    // indicate scanning in the title
    TextView status = (TextView) findViewById(R.id.bluetoothlist_status);
    status.setText(R.string.ble_startfind);

    // initialize bluetooth manager & adapter
    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothAdapter = bluetoothManager.getAdapter();
    bluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();

    // if bluetooth is not currently enabled,
    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }
    else {
        // initialize list view adapter
        deviceList = new ArrayList();
        mLeDeviceListAdapter = new LeDeviceListAdapter(this, R.layout.item_bluetoothdevice);
        listView_BluetoothList.setAdapter(mLeDeviceListAdapter);
        listView_BluetoothList.setOnItemClickListener(new ListViewItemClickListener());
        scanLeDevice(true);
    }
}
 
開發者ID:skydoves,項目名稱:MagicLight-Controller,代碼行數:32,代碼來源:SelectDeviceActivity.java

示例7: init

/**
 * Attempts to create the scanner.
 *
 * @param context
 * @return true if successful
 */
public boolean init(final Activity context) {
    // New Android M+ permission check requirement.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (context.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
                != PackageManager.PERMISSION_GRANTED) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("This app needs coarse location access");
            builder.setMessage("Please grant coarse location access so this app can scan for beacons");
            builder.setPositiveButton(android.R.string.ok, null);
            builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    ActivityCompat.requestPermissions(context, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
                            PERMISSION_REQUEST_COARSE_LOCATION);
                }
            });
            builder.show();
        }
    }
    BluetoothManager manager = (BluetoothManager) context.getApplicationContext()
            .getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothAdapter btAdapter = manager.getAdapter();
    if (btAdapter == null) {
        return false;
    } else if (!btAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        context.startActivityForResult(enableBtIntent, mRequestEnableBluetooth);
        return false;
    } else {
        scanner = btAdapter.getBluetoothLeScanner();
    }
    return true;
}
 
開發者ID:etsy,項目名稱:divertsy-client,代碼行數:39,代碼來源:BLEScanner.java

示例8: onStart

@Override
public void onStart() {
    super.onStart();
    if(D) Log.e(TAG, "++ ON START ++");

    // If BT is not on, request that it be enabled.
    // setupChat() will then be called during onActivityResult
    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
    // Otherwise, setup the chat session
    } else {
        if (mChatService == null) setupChat();
    }
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:15,代碼來源:BluetoothChat.java

示例9: checkBluetoothState

private boolean checkBluetoothState() {
    // TODO app freezes after enabling bluetooth through app instead of directly enabling it
    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        enableBtIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(enableBtIntent);
        Log.i("LOOP_THREAD", "Bluetooth not enabled..");
        return false;
    }
    return true;
}
 
開發者ID:ordsen,項目名稱:Snach-Android,代碼行數:11,代碼來源:BLEManager.java

示例10: init

public void init() {
    textViewLog = (TextView) findViewById(R.id.bluetooth_log);
    textViewLog.setMovementMethod(new ScrollingMovementMethod());

    btAdapter = BluetoothAdapter.getDefaultAdapter();
    if (btAdapter == null) {
        Log.w(TAG, "Bluetooth is not supported");
        showToast("Device does not support bluetooth");
        finish();
        return;
    }
    Log.i(TAG, "working bluetooth");
    if (!btAdapter.isEnabled()) {
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQUEST_BLUETOOTH);

        Log.e(TAG, "Bluetooth not enabled");
        return;
    }
    Log.i(TAG, "Bluetooth enabled");

    listPairedDevices.setAdapter(new DeviceAdapter(getApplicationContext(), btAdapter.getBondedDevices()));
    listPairedDevices.setOnItemClickListener(itemClickListener);

    dbHelper = new TrustChainDBHelper(getApplicationContext());
    kp = Key.loadKeys(getApplicationContext());

    //start listening for messages via bluetooth
    communication = new BluetoothCommunication(dbHelper, kp, this, btAdapter);
    communication.start();

}
 
開發者ID:wkmeijer,項目名稱:CS4160-trustchain-android,代碼行數:32,代碼來源:BluetoothActivity.java

示例11: enableBluetooth

/**
 * Asks to enable bluetooth
 */
@ReactMethod
public void enableBluetooth(final Promise promise) {
  try {
    if (!checkBluetooth()) {
      Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
      getReactApplicationContext().startActivityForResult(enableBtIntent, NEAR_BLUETOOTH_SETTINGS_CODE, new Bundle());
    }

    promise.resolve(true);
  } catch (Exception e) {
    promise.reject("BLE_ACTIVATION_ERROR", e.getMessage());
  }
}
 
開發者ID:nearit,項目名稱:react-native-connectivity-status,代碼行數:16,代碼來源:RNConnectivityStatusModule.java

示例12: startDiscovery

private void startDiscovery() {
    // Check if Bluetooth is enabled. If not, display a dialog requesting user permission to
    // enable Bluetooth.
    if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
        final Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);

        return;
    } // else: Bluetooth is enabled

    // On Android Marshmallow (6.0) and higher, we need ACCESS_COARSE_LOCATION or
    // ACCESS_FINE_LOCATION permission to get scan results, so check if we have. If not, ask the
    // user for permission
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (this.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(
                    new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
                    PERMISSION_REQUEST_COARSE_LOCATION
            );

            return;
        } // else: permission already granted
    } // else: running on older version of Android

    // Start scanning
    bluetoothAdapter.getBluetoothLeScanner().startScan(scanCallback);
}
 
開發者ID:SPINremote,項目名稱:sdc-1-quickstart-android,代碼行數:27,代碼來源:MainActivity.java

示例13: openBluetooth

/**
 * 開啟藍牙
 *
 * @param context
 */
public void openBluetooth(Activity context, int requestCode) {
    if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        context.startActivityForResult(enableBtIntent, requestCode);
    }
}
 
開發者ID:qiu-yongheng,項目名稱:Bluetooth_BLE,代碼行數:11,代碼來源:BleManager.java

示例14: onStart

@Override
public void onStart() {
    super.onStart();
    // If BT is not on, request that it be enabled.
    // setupChat() will then be called during onActivityResult
    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
        // Otherwise, setup the chat session
    } else if (mChatService == null) {
        setupChat();
    }
}
 
開發者ID:alexmerz,項目名稱:dab-iot,代碼行數:13,代碼來源:BluetoothChatFragment.java

示例15: onStart

@Override
public void onStart() {
    super.onStart();
    // If BT is not on, request that it be enabled.
    // setupChat() will then be called during onActivityResult
    if (null == mBluetoothAdapter || !mBluetoothAdapter.isEnabled()) {
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
        // Otherwise, setup the chat session
    } else if (mChatService == null) {
        setupChat();
    }
}
 
開發者ID:haraldh,項目名稱:iconsole-android,代碼行數:13,代碼來源:BluetoothChatFragment.java


注:本文中的android.bluetooth.BluetoothAdapter.ACTION_REQUEST_ENABLE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。