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


Java BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE属性代码示例

本文整理汇总了Java中android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE属性的典型用法代码示例。如果您正苦于以下问题:Java BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE属性的具体用法?Java BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE怎么用?Java BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.bluetooth.BluetoothAdapter的用法示例。


在下文中一共展示了BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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();
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:22,代码来源:SwapWorkflowActivity.java

示例2: 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);
		}
	}
}
 
开发者ID:BittleDragon,项目名称:BluetoothChatDemo,代码行数:26,代码来源:ServerActivity.java

示例3: 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);
    }
}
 
开发者ID:hardik-dadhich,项目名称:bluetooth-chat-appliction,代码行数:11,代码来源:BluetoothChatFragment.java

示例4: 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);
    }
}
 
开发者ID:paulinog,项目名称:SecretTalk,代码行数:11,代码来源:BluetoothChatFragment.java

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

示例6: 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;
	}
}
 
开发者ID:BittleDragon,项目名称:BluetoothChatDemo,代码行数:34,代码来源:ServerActivity.java

示例7: isDiscoverable

public boolean isDiscoverable(){
    if (mBluetoothAdapter != null)
        return mBluetoothAdapter.getScanMode() == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
    else
        return false;
}
 
开发者ID:n8fr8,项目名称:LittleBitLouder,代码行数:6,代码来源:BluetoothManager.java


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