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>
this sounds like you forgot to ask actively for the permission by an dialog: https://developer.radiusnetworks.com/2015/09/29/is-your-beacon-app-ready-for-android-6.html
Original idea found here: Bluetooth Low Energy startScan on Android 6.0 does not find devices
Greets
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
fileAnd 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'