當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。