【问题标题】:Android wifi and bluetooth scanning for locationAndroid wifi 和蓝牙扫描定位
【发布时间】:2019-07-30 19:13:28
【问题描述】:

是否有意图打开wifi和蓝牙扫描意图,要求用户提高定位精度?

更新:我找到了一种更好的方法来直接要求用户激活 Wifi 扫描这样做:

WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wifiManager.isScanAlwaysAvailable()==false) {
   startActivity(new Intent(WifiManager.ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE));
}

所以,我现在的问题是:我怎样才能做同样的事情来请求扫描始终可用于蓝牙?我应该使用什么 Intent?

到那个画面的方法如下:

对于牛轧糖:打开 Android 设置,转到位置,右上角的 3 点菜单,扫描。

对于奥利奥:打开 Android 设置,转到安全和位置、位置、扫描

对于 Pie:打开 Android 设置,转到位置、高级、扫描。

【问题讨论】:

    标签: android-location


    【解决方案1】:

    您可以使用LocationSettingsRequest 提示用户启用定位。在请求集builder.setNeedBle(true); 中启用蓝牙扫描。

    如果蓝牙已打开,则不会要求用户启用蓝牙扫描。

    【讨论】:

      【解决方案2】:

      持续扫描蓝牙可能会影响您的设备性能 和电池寿命。因此,请自行承担风险。

      即使在发现完成后,下面的代码也会继续检查设备。 首先,确保使用

      注册接收器
      IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); 
      registerReceiver(myReceiver, intentFilter);
      

      然后尝试运行代码。

      private BluetoothAdapter mBtAdapter;
      mBtAdapter.startDiscovery();
      
      private final BroadcastReceiver mReceiver = new BroadcastReceiver()
      {
              @Override
              public void onReceive(Context context, Intent intent)
              {
                  String action = intent.getAction();
      
                  // When discovery finds a device
                  if (BluetoothDevice.ACTION_FOUND.equals(action))
                  {
                  //do something
                  }
      
                  else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))
                  {
                      Log.v(TAG,"Entered the Finished ");
                      mBtAdapter.startDiscovery();
                  }
      

      【讨论】:

      • 我认为这不是我所问问题的答案。您的代码是搜索要配对的可用蓝牙设备的结果。我问的是另一件事。还是谢谢。
      • @Ton 你检查过this one吗?
      • 我想要找到的是这个屏幕:打开 Android 设置,转到位置、高级、扫描。查看我编辑的答案
      猜你喜欢
      • 1970-01-01
      • 2015-03-03
      • 2018-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-26
      相关资源
      最近更新 更多