Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

Bluetooth LE can't find any device on 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

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

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'
}

And my manifest file is:

<?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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Add this to your build.gradle file

implementation  com.android.support:appcompat-v7:28.0.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'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...