本文整理汇总了Java中android.bluetooth.BluetoothAdapter.getDefaultAdapter方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothAdapter.getDefaultAdapter方法的具体用法?Java BluetoothAdapter.getDefaultAdapter怎么用?Java BluetoothAdapter.getDefaultAdapter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.BluetoothAdapter
的用法示例。
在下文中一共展示了BluetoothAdapter.getDefaultAdapter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleProperty
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
private boolean handleProperty(final String key, final String value) {
if (key.equalsIgnoreCase("min.security_patch.bluetooth")) {
final String minSecurityPatchLevel = value;
log.info("according to \"{}\", minimum security patch level for bluetooth is {}", versionUrl,
minSecurityPatchLevel);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& Build.VERSION.SECURITY_PATCH.compareTo(minSecurityPatchLevel) < 0) {
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter != null && BluetoothAdapter.getDefaultAdapter().isEnabled()) {
handler.post(new Runnable() {
@Override
public void run() {
if (isAdded())
createInsecureBluetoothAlertDialog(minSecurityPatchLevel).show();
}
});
return true;
}
}
} else {
log.info("Ignoring key: {}", key);
}
return false;
}
示例2: ensureInit
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
private boolean ensureInit() {
if (mBluetoothAdapter == null) {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
if (mContext == null) {
if (LinphoneService.isReady()) {
mContext = LinphoneService.instance().getApplicationContext();
} else {
return false;
}
}
if (mContext != null && mAudioManager == null) {
mAudioManager = ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE));
}
return true;
}
示例3: isBluetoothEnabled
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* Check if bluetooth function enabled
*
* @param context the context
* @return true if bluetooth enabled
*/
public static boolean isBluetoothEnabled(@NonNull final Context context) {
final BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
if (bluetoothManager == null) {
return false;
}
final BluetoothAdapter bluetoothAdapter;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
bluetoothAdapter = bluetoothManager.getAdapter();
} else {
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
if (bluetoothAdapter == null) {
return false;
}
return bluetoothAdapter.isEnabled();
}
示例4: isBleSupported
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* Check if Bluetooth LE device supported on the running environment.
*
* @param context the context
* @return true if supported
*/
public static boolean isBleSupported(@NonNull final Context context) {
try {
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) == false) {
return false;
}
final BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
final BluetoothAdapter bluetoothAdapter;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
bluetoothAdapter = bluetoothManager.getAdapter();
} else {
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
if (bluetoothAdapter != null) {
return true;
}
} catch (final Throwable ignored) {
// ignore exception
}
return false;
}
示例5: onCreate
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(D) Log.e(TAG, "+++ ON CREATE +++");
// Set up the window layout
setContentView(R.layout.main);
// Get local Bluetooth adapter
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// If the adapter is null, then Bluetooth is not supported
if (mBluetoothAdapter == null) {
Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
finish();
return;
}
}
示例6: 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();
}
}
示例7: getBluetoothName
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public String getBluetoothName() {
try {
BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
if (defaultAdapter != null) {
return defaultAdapter.getName();
}
} catch (Throwable e) {
Ln.e(e);
}
return null;
}
示例8: IsBluetoothEnabled
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public boolean IsBluetoothEnabled() {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter != null) {
boolean isEnabled = bluetoothAdapter.isEnabled();
Logger.getInstance().Debug(TAG, String.format(Locale.getDefault(), "IsBluetoothEnabled: %s", isEnabled));
return isEnabled;
}
Logger.getInstance().Warning(TAG, "bluetoothAdapter is null!");
return false;
}
示例9: BluetoothMC
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* Required public constructor
*/
public BluetoothMC() {
newConnectionFlag++;
//get the mobile bluetooth device
myBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
HandleBluetoothStates();
}
示例10: connect
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* Connect to a remote Bluetooth socket, or throw an exception if it fails.
*/
private void connect() throws Exception {
Log.i(TAG, "Attempting connection to " + address + "...");
sendToReadHandler("CONNECTING");
// Get this device's Bluetooth adapter
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if ((adapter == null) || (!adapter.isEnabled())) {
throw new Exception("Bluetooth adapter not found or not enabled!");
}
// Find the remote device
BluetoothDevice remoteDevice = adapter.getRemoteDevice(address);
// Create a socket with the remote device using this protocol
socket = remoteDevice.createRfcommSocketToServiceRecord(uuid);
Log.i(TAG, "Socket Created.");
// Make sure Bluetooth adapter is not in discovery mode
adapter.cancelDiscovery();
// Connect to the socket
socket.connect();
// Get input and output streams from the socket
outStream = socket.getOutputStream();
inStream = socket.getInputStream();
Log.i(TAG, "Connected successfully to " + address + ".");
}
示例11: BluetoothChatService
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* Constructor. Prepares a new BluetoothChat session.
*
* @param context The UI Activity Context
* @param handler A Handler to send messages back to the UI Activity
*/
public BluetoothChatService(Context context, Handler handler) {
mAdapter = BluetoothAdapter.getDefaultAdapter();
mState = STATE_NONE;
mNewState = mState;
mHandler = handler;
}
示例12: BluetoothConnectionProvider
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public BluetoothConnectionProvider(ConnectionManager connectionManager) {
this.connectionManager = connectionManager;
this.thread = new Thread() {
public void run() {
Log.i(TAG, "Listen server started");
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
try {
serverSocket = btAdapter.listenUsingRfcommWithServiceRecord(PROTOCOL_SCHEME_RFCOMM, uuidSpp);
Log.d(TAG, "Server socket created");
while (serverSocket != null && btAdapter.isEnabled()) {
try {
BluetoothSocket bluetoothSocket = serverSocket.accept();
Socket socket = new BluetoothSocketAdapter(bluetoothSocket);
Log.i(TAG, ">>Connection opened (" + socket.getDestination() + ")");
BluetoothConnectionProvider.this.connectionManager.newConnection(socket);
} catch (IOException e) {
Log.e(TAG, "Error during accept", e);
Log.i(TAG, "Waiting 5 seconds before accepting again...");
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
}
}
}
} catch (IOException e) {
Log.e(TAG, "Error in listenUsingRfcommWithServiceRecord", e);
}
Log.i(TAG, "Listen server stopped");
}
};
}
示例13: 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");
}
}
示例14: init
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
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();
}
示例15: 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);
setStatus("None");
bluetoothDevicesAdapter = new BluetoothDevicesAdapter(this);
devicesListView.setAdapter(bluetoothDevicesAdapter);
devicesListView.setEmptyView(emptyListTextView);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
Log.e(Constants.TAG, "Device has no bluetooth");
new AlertDialog.Builder(MainActivity.this)
.setCancelable(false)
.setTitle("No Bluetooth")
.setMessage("Your device has no bluetooth")
.setPositiveButton("Close app", new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
Log.d(Constants.TAG, "App closed");
finish();
}
}).show();
}
//btn1.set
}