本文整理匯總了Java中android.bluetooth.BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE屬性的具體用法?Java BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE怎麽用?Java BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.bluetooth.BluetoothAdapter
的用法示例。
在下文中一共展示了BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendFDroid
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();
}
}
示例2: ensureBluetoothDiscoverableThenStart
private void ensureBluetoothDiscoverableThenStart() {
Utils.debugLog(TAG, "Ensuring Bluetooth is in discoverable mode.");
if (BluetoothAdapter.getDefaultAdapter().getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
// TODO: Listen for BluetoothAdapter.ACTION_SCAN_MODE_CHANGED and respond if discovery
// is cancelled prematurely.
// 3600 is new maximum! TODO: What about when this expires? What if user manually disables discovery?
final int discoverableTimeout = 3600;
Utils.debugLog(TAG, "Not currently in discoverable mode, so prompting user to enable.");
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, discoverableTimeout);
startActivityForResult(intent, REQUEST_BLUETOOTH_DISCOVERABLE);
}
if (service == null) {
throw new IllegalStateException("Can't start Bluetooth swap because service is null for some strange reason.");
}
service.getBluetoothSwap().startInBackground();
}
示例3: makeDiscoverable
public void makeDiscoverable() {
if (mBluetoothAdapter == null) {
return;
} else {
if (mBluetoothAdapter.isEnabled() && isDiscoverable()) {
Log.e("", "===> mBluetoothAdapter.isDiscoverable()");
return;
} else {
Log.e("", "===> makeDiscoverable");
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, mTimeDiscoverable);
mActivity.startActivityForResult(discoverableIntent, REQUEST_DISCOVERABLE_CODE);
}
}
}
示例4: initBluetooth
private void initBluetooth() {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {//設備不支持藍牙
Toast.makeText(getApplicationContext(), "設備不支持藍牙", Toast.LENGTH_LONG).show();
finish();
return;
}
//判斷藍牙是否開啟
if (!mBluetoothAdapter.isEnabled()) {//藍牙未開啟
Intent enableIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
//mBluetoothAdapter.enable();此方法直接開啟藍牙,不建議這樣用。
}
//設置藍牙可見性
if (mBluetoothAdapter.isEnabled()) {
if (mBluetoothAdapter.getScanMode() !=
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
Intent discoverableIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(
BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120);
startActivity(discoverableIntent);
}
}
}
示例5: onNearby
@Override
public void onNearby() {
// If Bluetooth has not been enabled/turned on, then
// enabling device discoverability will automatically enable Bluetooth
Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 121);
startActivityForResult(discoverBt, REQUEST_ENABLE_BLUETOOTH);
// if this is successful, the Bluetooth transfer is started
}
示例6: ensureDiscoverable
/**
* Makes this device discoverable for 300 seconds (5 minutes).
*/
private void ensureDiscoverable() {
if (mBluetoothAdapter.getScanMode() !=
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
}
}
示例7: ensureDiscoverable
/**
* Makes this device discoverable for 300 seconds (5 minutes).
*/
public void ensureDiscoverable() {
if (mBluetoothAdapter.getScanMode() !=
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
}
}
示例8: ensureDiscoverable
private void ensureDiscoverable() {
if(D) Log.d(TAG, "ensure discoverable");
if (mBluetoothAdapter.getScanMode() !=
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
}
}
示例9: makeBluetoothDiscoverable
/**
* Asks to the user to make the bluetooth discoverable in order to be able to find the other players.
*/
public static void makeBluetoothDiscoverable() {
System.out.println("Started");
System.out.println(started);
if(started) {
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 60);
mainActivity.startActivity(discoverableIntent);
}
}
示例10: discoverable
/**
* 設置當前設備可被其他設備檢測
* 應用可以設置的最大持續時間為 3600 秒,值為 0 則表示設備始終可檢測到。 任何小於 0 或大於 3600 的值都會自動設為 120 秒
*/
private void discoverable() {
Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
startActivity(discoverableIntent);
}
示例11: onOptionsItemSelected
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.enable_visibility:
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
enableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 600);
startActivityForResult(enableIntent, Params.REQUEST_ENABLE_VISIBILITY);
break;
case R.id.discovery:
if (bluetoothAdapter.isDiscovering()) {
bluetoothAdapter.cancelDiscovery();
}
if (Build.VERSION.SDK_INT >= 6.0) {
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
Params.MY_PERMISSION_REQUEST_CONSTANT);
}
bluetoothAdapter.startDiscovery();
break;
case R.id.disconnect:
bluetoothAdapter.disable();
deviceList.clear();
listAdapter.notifyDataSetChanged();
toast("藍牙已關閉");
break;
}
return super.onOptionsItemSelected(item);
}
示例12: onClick
@Override
public void onClick(View arg0) {
switch(arg0.getId()){
case R.id.btn_blth_visiblity:
if (mBluetoothAdapter.isEnabled()) {
if (mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
Intent discoveryIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoveryIntent.putExtra(
BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoveryIntent);
}
}else {
Toast.makeText(getApplicationContext(), getResources().getString(R.string.bluetooth_unopened), Toast.LENGTH_SHORT).show();
}
break;
case R.id.btn_blth_disconnect:
if (mBlthChatUtil.getState() != BluetoothChatUtil.STATE_CONNECTED) {
Toast.makeText(mContext, "藍牙未連接", Toast.LENGTH_SHORT).show();
}else {
mBlthChatUtil.disconnect();
}
break;
case R.id.btn_sendmessage:
String messagesend = mEdttMessage.getText().toString();
if(null == messagesend || messagesend.length() == 0){
return;
}
mBlthChatUtil.write(messagesend.getBytes());
break;
default:
break;
}
}
示例13: enableDiscoverable
/**
* Enable the current {@link BluetoothAdapter} to be discovered (available for pairing) for
* the next {@link #DISCOVERABLE_TIMEOUT_MS} ms.
*/
private void enableDiscoverable() {
Log.d(TAG, "Registering for discovery.");
Intent discoverableIntent =
new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,
DISCOVERABLE_TIMEOUT_MS);
startActivityForResult(discoverableIntent, REQUEST_CODE_ENABLE_DISCOVERABLE);
}
示例14: onOptionsItemSelected
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.set_visible:
Intent visibleIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
visibleIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120);
startActivity(visibleIntent);
Toast.makeText(this, "請返回應用以授權", Toast.LENGTH_LONG).show();
//register scanModeReceiver
scanModeReceiverRegistered = true;
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
registerReceiver(scanModeReceiver, intentFilter);
case R.id.settings:
/*
//Go to system settings
Intent settingsIntent = new Intent();
settingsIntent.setAction(Settings.ACTION_BLUETOOTH_SETTINGS);
settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(settingsIntent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
Toast.makeText(this, "Failed going to settings", Toast.LENGTH_SHORT).show();
}
*/
Intent intent = new Intent(this, SettingsFragment.class);
startActivity(intent);
break;
case R.id.about:
Toast.makeText(this, "Written by kevin-vista", Toast.LENGTH_SHORT).show();
break;
case R.id.feedback:
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:[email protected]"));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback - Bluetooth Scanner");
startActivity(emailIntent);
default:
break;
}
return true;
}