扩展Android的蓝牙可发现 [英] Extend Android Bluetooth Discoverability

查看:142
本文介绍了扩展Android的蓝牙可发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写依赖于Android设备上(对于我目前的测试目的是HTC EVO 4G和几个原摩托罗拉机器人),通过蓝牙300秒被发现的应用程序。

I am writing an application that relies on the Android device (for my current testing purposes an HTC Evo 4G and several original Motorola Droids) being discoverable via bluetooth for 300 seconds.

我靶向Android版本2.0.1,所以根据API我应该能够提示用户使可发现最多的300秒。在我的两个机器人和我的Evo提示窗口列出了300秒,但他们在120秒后两端。

I am targeting Android version 2.0.1, so according to the API I should be able to prompt the user to enable discoverability for a maximum of 300 seconds. On both my Droids and my Evo the prompt window has 300 seconds listed, but they both end after 120 seconds.

在code我用来提示用户是在这里:

The code I used to prompt the user is here:

private void makeDiscoverable() {
    Intent discoverableIntent = new Intent(
            BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    discoverableIntent.putExtra(
            BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
    startActivity(discoverableIntent);
}

我敢肯定,这code运行。不过,后来我有一个处理程序时,我发现性状况的改变(在这种情况下结束,我假设),用于读取这样的:

I am certain that this code runs. However, I later have a handler for when my discoverability status changes (in this case ends, I assume) that reads like this:

if (isDiscoverableChange(action)) {
            int discoverState = intent.getIntExtra(
                    BluetoothAdapter.EXTRA_SCAN_MODE, Short.MIN_VALUE);
            if (isDiscoverableState(discoverState)) {
                setItOrder();
                setUpScanAndDisplay();
            } else {
                discoverScheduler.cancel();
                itScheduler.cancel();
            }
        }

private boolean isDiscoverableChange(String action) {
    return BluetoothAdapter.ACTION_SCAN_MODE_CHANGED.equals(action);
}

private boolean isDiscoverableState(int state) {
    return state == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
}

我想评论的是,当可发现模式结束,以防它被取消一切prematurely运行的部分,但可发现确实在120秒后结束。

I tried commenting out the portion that runs when discoverability mode ends, just in case it was cancelling everything prematurely, but discoverability really does end after 120 seconds.

这是一个硬件问题,还是我做错了什么吗?

Is this a hardware issue, or am I doing something wrong here?

推荐答案

这似乎是一个错误:

问题15486:蓝牙Adapter.EXTRA发现没有听从 HTTP://$c$c.google.com/p /安卓/问题/详细信息?ID = 15486

Issue 15486: Bluetooth Adapter.EXTRA DISCOVERABLE not obeyed http://code.google.com/p/android/issues/detail?id=15486

问题13361:BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION意图外没有延伸120秒发现间隔 HTTP://$c$c.google.com/p /安卓/问题/详细信息?ID = 13361

Issue 13361: BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION intent Extra does not extend 120 sec discovery interval http://code.google.com/p/android/issues/detail?id=13361

首先报道2010年12月22号,仍然被列为新的状态,所以我不希望这是固定的。

First reported Dec 22, 2010, still listed as 'new' status, so I wouldn't expect this to be fixed.

这篇关于扩展Android的蓝牙可发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆