蓝牙LE在android 6.0上找不到任何设备 [英] Bluetooth LE can't find any device on android 6.0

本文介绍了蓝牙LE在android 6.0上找不到任何设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个从蓝牙设备接收数据并在4.4.4 android智能手机上具有全部功能的应用程序.但是,当我在6.0版设备上尝试时,找不到蓝牙设备.我已经在手机上激活了位置信息,并添加了清单文件中的位置信息许可权,但没有任何反应.

I am building an app that receives data from bluetooth device and is fully functional on a 4.4.4 android smartphone. But when I try it on version 6.0 devices it does not find the bluetooth devices. I have activated location on the phone and I have added the permissions for location on manifest file but nothing happens.

我在某处阅读过我必须请求用户许可的内容,并且尝试添加

I have read somewhere that I have to request permission from the user and I have tried to add

ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 1001); //Any number

关于我的活动的onCreate,但出现错误无法解析符号AcivityCompat"和无法解析符号清单" ...

on my activity's onCreate, but I get error "cannot resolve symbol AcivityCompat" and "cannot resolve symbol Manifest"...

我的build.gradle文件是:

My build.gradle file is that:

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
    applicationId "com.redbear.chat"
    minSdkVersion 18
    targetSdkVersion 26
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

dependencies {
implementation 'com.android.support:support-v4:28.+'
implementation 'com.google.android.gms:play-services-location:16.0.0'
}

我的清单文件是:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.redbear.chat"
android:versionCode="1"
android:versionName="1.0" >

<uses-feature
    android:name="android.hardware.bluetooth_le"
    android:required="true" />

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Needed only if your app targets Android 5.0 (API level 21) or higher. -->
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.location.network" />



<application
    android:allowBackup="true"
    android:icon="@drawable/redbear"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.redbear.chat.Main"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.redbear.chat.Chat"
        android:windowSoftInputMode="stateHidden" >
    </activity>
    <activity
        android:name=".Device"
        android:theme="@android:style/Theme.Dialog" >
    </activity>

    <service
        android:name="com.redbear.chat.RBLService"
        android:enabled="true" />
</application>

</manifest>

推荐答案

是的,您必须询问并被授予那些权限,否则在运行时不会显示任何内容.但是我看到的是您缺少对AppCompat

Yes you have to ask and be granted those permissions or else nothing will show up under runtime. But what i can see is that you are missing some dependencies on AppCompat

将此添加到您的build.gradle文件

implementation  com.android.support:appcompat-v7:28.0.0

也不要使用隐式版本号,这将/可能导致无法预料的错误,因为它可以随时升级,而无需您知道和引入讨厌的错误. 始终使用明确的数字进行设置 'com.android.support:support-v4:28.0'

And also don't use implicit version number this will/can cause unpredicted errors because it can upgrade whenever without you knowing and introducing a nasty bug. Set it always with a explicit number 'com.android.support:support-v4:28.0'

这篇关于蓝牙LE在android 6.0上找不到任何设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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