本文整理匯總了Java中android.bluetooth.BluetoothManager.getAdapter方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothManager.getAdapter方法的具體用法?Java BluetoothManager.getAdapter怎麽用?Java BluetoothManager.getAdapter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.bluetooth.BluetoothManager
的用法示例。
在下文中一共展示了BluetoothManager.getAdapter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setupBleController
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
boolean setupBleController() {
boolean retvalue = true;
if(bluetoothAdapter == null) {
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
bluetoothAdapter = bluetoothManager.getAdapter();
retvalue = false;
}
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && leScanner == null) {
if(bluetoothAdapter == null) {
retvalue = false;
} else {
leScanner = bluetoothAdapter.getBluetoothLeScanner();
if(leScanner == null)
retvalue = false;
}
}
return retvalue;
}
示例2: onCreate
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setTitle(R.string.title_devices);
mHandler = new Handler();
// Use this check to determine whether BLE is supported on the device. Then you can
// selectively disable BLE-related features.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
finish();
}
// Initializes a Bluetooth adapter. For API level 18 and above, get a reference to
// BluetoothAdapter through BluetoothManager.
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
// Checks if Bluetooth is supported on the device.
if (mBluetoothAdapter == null) {
Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show();
finish();
return;
}
}
示例3: onCreate
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
// mBluetoothAdapterの取得
mBluetoothAdapter = bluetoothManager.getAdapter();
// mBluetoothLeScannerの初期化
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
Uri.Builder builder = new Uri.Builder();
AsyncHttpRequest task = new AsyncHttpRequest(this);
task.execute(builder);
scan(true);
}
示例4: onStartCommand
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS))
throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key");
final Uri logUri = intent.getParcelableExtra(EXTRA_LOG_URI);
mLogSession = Logger.openSession(getApplicationContext(), logUri);
mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
Logger.i(mLogSession, "Service started");
// notify user about changing the state to CONNECTING
final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING);
LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast);
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
final BluetoothAdapter adapter = bluetoothManager.getAdapter();
final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress);
mDeviceName = device.getName();
onServiceStarted();
mBleManager.connect(device);
return START_REDELIVER_INTENT;
}
示例5: onReceive
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
@TargetApi(18)
public void onReceive(Context context, Intent intent) {
if (VERSION.SDK_INT >= 18) {
if (QNApiImpl.this.mBluetoothAdapter == null) {
BluetoothManager bluetoothManager = (BluetoothManager) QNApiImpl.this
.mContext.getSystemService("bluetooth");
QNApiImpl.this.mBluetoothAdapter = bluetoothManager.getAdapter();
}
if (QNApiImpl.this.mBluetoothAdapter != null && !QNApiImpl.this.mBluetoothAdapter
.isEnabled()) {
QNApiImpl.this.bleScan.onBleClosed(QNApiImpl.this.mBluetoothAdapter);
for (QNBleHelper bleHelper : QNApiImpl.this.helperMap.values()) {
if (!(bleHelper == null || bleHelper.bleCallback == null)) {
bleHelper.bleCallback.onCompete(7);
}
}
}
}
}
示例6: isBluetoothEnabled
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
private boolean isBluetoothEnabled() {
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
if (bluetoothAdapter == null) {
Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_LONG).show();
finish();
}
boolean enabled = true;
if (!bluetoothAdapter.isEnabled()) {
enabled = false;
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, ENABLE_BLUETOOTH);
}
return enabled;
}
示例7: onCreate
import android.bluetooth.BluetoothManager; //導入方法依賴的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();
}
}
示例8: checkBluetooth
import android.bluetooth.BluetoothManager; //導入方法依賴的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();
}
示例9: onCreate
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDevices = (ListView) findViewById(R.id.lv_devices);
BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
if (mBluetoothAdapter == null) {
Toast.makeText(getApplicationContext(), "Bluetooth device unavailable!",Toast.LENGTH_SHORT).show();
finish();
}
mHandler = new Handler();
}
示例10: attemptConnection
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
public void attemptConnection() {
mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
if (device != null) {
details.append("\nConnection state: " + " Device is not null");
mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
}
Log.i(TAG, "Connection state: " + mConnectionState);
details.append("\nConnection state: " + mConnectionState);
if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class)
.orderBy("_ID desc")
.executeSingle();
if (btDevice != null) {
details.append("\nBT Device: " + btDevice.name);
mDeviceName = btDevice.name;
mDeviceAddress = btDevice.address;
mBluetoothAdapter = mBluetoothManager.getAdapter();
boolean newConnection = true;
if(newConnection) {
is_connected = connect(mDeviceAddress);
details.append("\nConnecting...: ");
}
}
}
}
示例11: onStartCommand
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS))
throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key");
mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
// notify user about changing the state to CONNECTING
final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING);
LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast);
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
final BluetoothAdapter adapter = bluetoothManager.getAdapter();
final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress);
mDeviceName = device.getName();
mBleManager.connect(device);
return START_REDELIVER_INTENT;
}
示例12: onCreate
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
mHandler = new Handler();
mLView = (ListView) findViewById(R.id.scan_device_lv);
// 判斷硬件是否支持藍牙4.0
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
finish();
}
// 獲取藍牙適配器
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
// 判斷設備是否支持藍牙
if (mBluetoothAdapter == null) {
Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show();
finish();
}
}
示例13: setupBluetooth
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
private void setupBluetooth() {
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
bluetoothAdapter = bluetoothManager.getAdapter();
if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, ACTIVITY_RESULT_BLUETOOTH_REQUESTED);
} else {
info("Bluetooth activated");
}
}
示例14: init
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
/**
* 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;
}
示例15: BluetoothChecker
import android.bluetooth.BluetoothManager; //導入方法依賴的package包/類
private BluetoothChecker() {
if(mBluetoothAdapter == null) {
final BluetoothManager bluetoothManager = (BluetoothManager) MBApp.getApp().getSystemService(Context
.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
}
}