【问题标题】:android studio - Bluetooth don't find mobile's bluetoothandroid studio - 蓝牙找不到手机的蓝牙
【发布时间】:2020-10-22 18:07:02
【问题描述】:

我在 android studio 上,我已经实现了一个工作不完全正常的蓝牙活动。我的意思是,当我开始发现时,扫描能够找到 Tv 、 bbox ......但它没有找到任何 iphone 或 android 蓝牙,尽管它们是可发现的......

有人遇到过这个问题吗?需要特别许可吗?

这里是已经设置的权限

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

提前致谢:)

【问题讨论】:

    标签: java android android-studio bluetooth android-bluetooth


    【解决方案1】:

    我在这篇文章中找到了答案:

    Android - Bluetooth discovery doesn't find any device

    对我来说,似乎让位置无法让我的应用发现其他设备.. 我仍在使用它。 欢迎评论:)

    【讨论】:

      【解决方案2】:

      您的权限是正确的,但是当您想要发现可用的蓝牙设备时,您需要显示位置访问权限。这是在 Android 上进行位置访问的程序。如果您使用按钮/其他,请调用函数 statusCheck()。

      private void statusCheck() {
          final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
          if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
              buildAlertMessageNoGps();
          }
      }
      
      private void buildAlertMessageNoGps() {
          final AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setMessage("Location access is required to search for devices, do you want to activate ?")
                  .setCancelable(false)
                  .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                      public void onClick(final DialogInterface dialog, final int id) {
                          startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                      }
                  })
                  .setNegativeButton("No", new DialogInterface.OnClickListener() {
                      public void onClick(final DialogInterface dialog, final int id) {
                          dialog.cancel();
                      }
                  });
          final AlertDialog alert = builder.create();
          alert.show();
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-25
        • 1970-01-01
        相关资源
        最近更新 更多