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


Java BluetoothAdapter.getDefaultAdapter方法代码示例

本文整理汇总了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;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:25,代码来源:AlertDialogsFragment.java

示例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;
}
 
开发者ID:treasure-lau,项目名称:Linphone4Android,代码行数:17,代码来源:BluetoothManager.java

示例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();
}
 
开发者ID:kshoji,项目名称:BLE-HID-Peripheral-for-Android,代码行数:27,代码来源:BleUtils.java

示例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;
}
 
开发者ID:kshoji,项目名称:BLE-HID-Peripheral-for-Android,代码行数:30,代码来源:BleUtils.java

示例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;
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:19,代码来源:BluetoothChat.java

示例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();
    }
}
 
开发者ID:RockyQu,项目名称:MVVMFrames,代码行数:16,代码来源:DeviceUtils.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:12,代码来源:DeviceHelper.java

示例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;
}
 
开发者ID:GuepardoApps,项目名称:LucaHome-AndroidApplication,代码行数:11,代码来源:BluetoothController.java

示例9: BluetoothMC

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
 * Required public constructor
 */
public BluetoothMC() {
    newConnectionFlag++;

    //get the mobile bluetooth device
    myBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    HandleBluetoothStates();
}
 
开发者ID:Ahmed-Abdelmeged,项目名称:Android-BluetoothMCLibrary,代码行数:11,代码来源:BluetoothMC.java

示例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 + ".");

}
 
开发者ID:aidaferreira,项目名称:synesthesiavision,代码行数:35,代码来源:BluetoothThread.java

示例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;
}
 
开发者ID:alexmerz,项目名称:dab-iot,代码行数:13,代码来源:BluetoothChatService.java

示例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");
        }
    };
}
 
开发者ID:RomascuAndrei,项目名称:BTNotifierAndroid,代码行数:35,代码来源:BluetoothConnectionProvider.java

示例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");
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:10,代码来源:BluetoothTetheringTile.java

示例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();

}
 
开发者ID:wkmeijer,项目名称:CS4160-trustchain-android,代码行数:33,代码来源:BluetoothActivity.java

示例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
}
 
开发者ID:bilal-rashid,项目名称:Lazy-Switches,代码行数:36,代码来源:MainActivity.java


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