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


Java BluetoothDevice.ACTION_FOUND属性代码示例

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


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

示例1: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    switch (action) {
        case BluetoothDevice.ACTION_FOUND:
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            Log.d(TAG, "ACTION_FOUND: " + device.getName());
            if (device.getName() != null && TARGET_DEVICE_NAME.contains(device.getName())) {
                Log.d(TAG, "target device found..");
                mTargetDevices.add(device);
            }
            break;
        case BluetoothDevice.ACTION_BOND_STATE_CHANGED:
            int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
            int previousState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, -1);

            Log.d(TAG, "ACTION_BOND_STATE_CHANGED: state:" + state + ", previous:" + previousState);

            break;
    }
}
 
开发者ID:casper-kim,项目名称:androidthings-bluetooth-pairing,代码行数:22,代码来源:MainActivity.java

示例2: startBluetoothServices

/**
 * Starts bluetooth and listens to pairing requests and bluetooth state changes
 */
public static void startBluetoothServices() {
    mReceiver = new BluetoothReceiver();
    //Register the BroadcastReceiver for multiple bluetooth actions

    //when another bluetooth device is discovered in range
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

    //when discovering action finishes (discovering means that bluetooth searches for nearby devices)
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    //when bluetooth changes from on to off
    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);

    //when another device requests pairing with this device
    filter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST);

    mainActivity.mainRegisterReceiver(mReceiver, filter);

    if(!started) {
        //tries to start bluetooth if it is not on
       mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if(mBluetoothAdapter!=null){
            if (!mBluetoothAdapter.isEnabled()) {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                mainActivity.startActivityForResult(enableBtIntent, MainActivity.BLUETOOTH_ON);
            } else {
                started = true;
            }
        }

    }
}
 
开发者ID:mcr222,项目名称:pass_the_bomb,代码行数:34,代码来源:BluetoothServices.java

示例3: onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bluetooth);
    listView = (ListView) findViewById(R.id.listview);
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    registerReceiver(mReceiver, filter);
    mArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1);
    listView.setAdapter(mArrayAdapter);
    //1.获取BluetoothAdapter;
    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter != null) {
        //2.启用蓝牙
        if (!bluetoothAdapter.isEnabled()) {
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
        } else {
            //查询配对信息
            findDevice();
            discoverable();
        }
    } else {
        // 不支持蓝牙
        Toast.makeText(this, "不支持蓝牙设备", Toast.LENGTH_LONG).show();
    }
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:26,代码来源:BluetoothActivity.java

示例4: scanNetworks

@ProtoMethod(description = "Scan bluetooth networks. Gives back the name, mac and signal strength", example = "")
@ProtoMethodParam(params = {"function(name, macAddress, strength)"})
public void scanNetworks(final ReturnInterface callbackfn) {
    MLog.d(TAG, "scanNetworks");
    start();

    mAdapter.startDiscovery();
    BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

                int rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE);

                ReturnObject o = new ReturnObject();
                String name = device.getName();
                if (name == null) name = "";

                o.put("name", name);
                o.put("mac", device.getAddress());
                o.put("strength", rssi);
                callbackfn.event(o);
            }
        }
    };

    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    getContext().registerReceiver(mReceiver, filter);

}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:32,代码来源:PBluetooth.java

示例5: onCreateView

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view=LayoutInflater.from(getActivity()).inflate(R.layout.fragment_linkdevice,container,false);
    //mBtn_searchBle= (Button) view.findViewById(R.id.btn_search);
    mCpb_connect= (CircularProgressButton) view.findViewById(R.id.cpb_connect);
    iv_connect= (ImageView) view.findViewById(R.id.iv_conntect);
    adapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_list_item_1, mArrayList);
    locationUtils=new LocationUtils(getApplicationContext());
    vibrator = (Vibrator) getActivity(). getSystemService(VIBRATOR_SERVICE);
    mApplication= (MyApplication) getActivity().getApplication();
    mCpb_connect.setIndeterminateProgressMode(true);
    mCpb_connect.setOnClickListener(new mCpb_connectClick());
    //打开蓝牙
    openBtDevice();
    // 动态注册广播接收器
    // 用来接收扫描到的设备信息
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    getActivity().registerReceiver(mReceiver, filter);
    return view;
}
 
开发者ID:fergus825,项目名称:SmartOrnament,代码行数:23,代码来源:LinkDeviceFragment.java

示例6: onReceive

/**
 * {@inheritDoc}
 */
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Log.d(TAG, "Incoming intent : " + action);
    switch (action) {
        case BluetoothDevice.ACTION_FOUND :
            // Discovery has found a device. Get the BluetoothDevice
            // object and its info from the Intent.
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            Log.d(TAG, "Device discovered! " + BluetoothController.deviceToString(device));
            listener.onDeviceDiscovered(device);
            break;
        case BluetoothAdapter.ACTION_DISCOVERY_FINISHED :
            // Discovery has ended.
            Log.d(TAG, "Discovery ended.");
            listener.onDeviceDiscoveryEnd();
            break;
        case BluetoothAdapter.ACTION_STATE_CHANGED :
            // Discovery state changed.
            Log.d(TAG, "Bluetooth state changed.");
            listener.onBluetoothStatusChanged();
            break;
        case BluetoothDevice.ACTION_BOND_STATE_CHANGED :
            // Pairing state has changed.
            Log.d(TAG, "Bluetooth bonding state changed.");
            listener.onDevicePairingEnded();
            break;
        default :
            // Does nothing.
            break;
    }
}
 
开发者ID:aurasphere,项目名称:blue-pair,代码行数:35,代码来源:BroadcastReceiverDelegator.java

示例7: onReceive

public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    switch (action) {
        case BluetoothAdapter.ACTION_DISCOVERY_STARTED:
            mDeviceList = new ArrayList<>();
            showProgress("", mContext.getString(R.string.searching_bluetooth_devices));
            break;
        case BluetoothAdapter.ACTION_DISCOVERY_FINISHED:
            performDiscoveryFinishedAction();
            break;
        case BluetoothDevice.ACTION_FOUND:
            performActionFound(intent);
            break;
        case BluetoothDevice.ACTION_BOND_STATE_CHANGED: {
            performBondStateChangeAction(intent);
            break;
        }
        default:
            break;

    }
}
 
开发者ID:Welloculus,项目名称:MobileAppForPatient,代码行数:22,代码来源:BluetoothHandler.java

示例8: scanAroundDevices

private void scanAroundDevices()
{
    displayLog("Intentando escanerar dispositivos...");

    if (mReceiver == null)
    {
        // Register the BroadcastReceiver
        mReceiver = new DeviceBroadcastReceiver();
        IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
        registerReceiver(mReceiver, filter);
    }

    // Start scanning
    mBluetoothAdapter.startDiscovery();
}
 
开发者ID:Mozta,项目名称:ELM327,代码行数:15,代码来源:MainActivity.java

示例9: find

@Override
public void find() {
    AfterEnable afterEnableFind = new AfterEnable() {
        @Override
        public void after() {
            find();
        }
    };

    if (!enable(afterEnableFind)) {
        return;
    }
    if (findInProgress) {
        return;
    }

    onStatusChange(BluetoothStatus.Searching);
    stopFindTask = new TimerTask() {
        @Override
        public void run() {
            cancelFind();
            stopFindTask = null;
        }
    };

    // stop find after 2 minutes.
    stopFindTimer = new Timer();
    stopFindTimer.schedule(stopFindTask, 120 * 1000);

    // Register for broadcasts when a device is discovered.
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    app.registerReceiver(mReceiver, filter);

    findInProgress = true;
    mBt.startDiscovery();
}
 
开发者ID:e-regular-games,项目名称:arduator,代码行数:36,代码来源:ArduinoCommManagerBt.java

示例10: btDiscoverAndGetResults

@Rpc(
    description =
            "Start discovery, wait for discovery to complete, and return results, which is a list of "
                    + "serialized BluetoothDevice objects."
)
public List<Bundle> btDiscoverAndGetResults()
        throws InterruptedException, BluetoothAdapterSnippetException {
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    if (mBluetoothAdapter.isDiscovering()) {
        mBluetoothAdapter.cancelDiscovery();
    }
    mDiscoveryResults.clear();
    mIsScanResultAvailable = false;
    BroadcastReceiver receiver = new BluetoothScanReceiver();
    mContext.registerReceiver(receiver, filter);
    try {
        if (!mBluetoothAdapter.startDiscovery()) {
            throw new BluetoothAdapterSnippetException(
                    "Failed to initiate Bluetooth Discovery.");
        }
        if (!Utils.waitUntil(() -> mIsScanResultAvailable, 120)) {
            throw new BluetoothAdapterSnippetException(
                    "Failed to get discovery results after 2 mins, timeout!");
        }
    } finally {
        mContext.unregisterReceiver(receiver);
    }
    return btGetCachedScanResults();
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:30,代码来源:BluetoothAdapterSnippet.java

示例11: onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.device_finder_layout);

    android.widget.Button btnConnect = (android.widget.Button) findViewById(R.id.btn_connect);
    TextView tvDevice = (TextView) findViewById(R.id.tv_device);

    btnConnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(!deviceAddress.isEmpty())
                connect();
        }
    });
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    if (mBluetoothAdapter == null) {
        Log.w(TAG, "No default Bluetooth adapter. Device likely does not support bluetooth.");
        return;
    }

    if(!mBluetoothAdapter.isEnabled()){
        Log.w(TAG, "Enable BT");
        mBluetoothAdapter.enable();
    }

    Set<BluetoothDevice> allDevices = mBluetoothAdapter.getBondedDevices();
    for(BluetoothDevice d: allDevices){
        if(isNanoHubDevice(d)){
            myDevices.add(d);
        }
    }

    Log.w(TAG, "myDevices size = " + myDevices.size());
    if(myDevices.size() == 0){
        Toast.makeText(this, "No device found", Toast.LENGTH_LONG).show();
        // If no device was already paired let's try to discover
        Log.w(TAG, "No device found");
        IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
        registerReceiver(mReceiver, filter);
        if(mBluetoothAdapter.isDiscovering()){
            mBluetoothAdapter.cancelDiscovery();
        }
        myDevices.clear();
        Boolean stat = mBluetoothAdapter.startDiscovery();
        if(stat)
            Log.w(TAG, "discovering started");
        else
            Log.w(TAG, "Could not start discovery");
    }else {

        tvDevice.setText("Device: " + myDevices.get(0).getName() + "\t" + myDevices.get(0).getAddress());
        deviceAddress = myDevices.get(0).getAddress();

    }
    if(mBluetoothAdapter.isDiscovering()){
        mBluetoothAdapter.cancelDiscovery();
    }
}
 
开发者ID:mhanuel26,项目名称:gym-tracker-infineon,代码行数:60,代码来源:DeviceFinderActivity.java


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