Skip to content

Commit d6d3cfe

Browse files
committed
Android 12 changes
1 parent fcf20d7 commit d6d3cfe

17 files changed

Lines changed: 496 additions & 185 deletions

.idea/gradle.xml

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,26 @@ Flic2Manager.getInstance().startScan(new Flic2ScanCallback() {
100100

101101
If the scan times out or otherwise fails for some reason, `onComplete` will be called with an error code as result, defined in `Flic2ScanCallback` or `Flic2ButtonListener`.
102102

103-
Before scanning however, we need to acquire the `Manifest.permission.ACCESS_FINE_LOCATION` permission by asking the user. This is due to a requirement of the Android platform in order to scan for Bluetooth Low Energy devices.
103+
Before scanning however, we need to acquire some runtime permission by asking the user. This is due to a requirement of the Android platform in order to scan for/connect to Bluetooth Low Energy devices.
104+
If targeting and running on Android 12 or higher `Manifest.permission.BLUETOOTH_SCAN` and `Manifest.permission.BLUETOOTH_CONNECT` are required. Otherwise `Manifest.permission.ACCESS_FINE_LOCATION` is required.
104105
In your activity, use the following code:
105106

106107
```java
107-
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
108-
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
109-
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
110-
return;
108+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
109+
if (Build.VERSION.SDK_INT < 31) {
110+
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
111+
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
112+
return;
113+
}
114+
} else {
115+
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED ||
116+
ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED)
117+
{
118+
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT}, 1);
119+
return;
120+
}
121+
}
111122
}
112-
113123
// if this line is reached, the permission was already granted and we can now start scan
114124
```
115125

@@ -119,10 +129,18 @@ The `requestPermissions` call will open a popup where the user must press Allow.
119129
@Override
120130
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
121131
if (requestCode == 1) {
122-
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
123-
// now startScan can be safely called
132+
if (Build.VERSION.SDK_INT < 31) {
133+
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
134+
// now startScan can be safely called
135+
} else {
136+
Toast.makeText(getApplicationContext(), "Scanning needs Location permission, which you have rejected", Toast.LENGTH_SHORT).show();
137+
}
124138
} else {
125-
Toast.makeText(getApplicationContext(), "Scanning needs Location permission, which you have rejected", Toast.LENGTH_SHORT).show();
139+
if (grantResults.length >= 2 && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
140+
// now startScan can be safely called
141+
} else {
142+
Toast.makeText(getApplicationContext(), "Scanning needs permissions for finding nearby devices, which you have rejected", Toast.LENGTH_SHORT).show();
143+
}
126144
}
127145
}
128146
}

build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
buildscript {
44
repositories {
5+
mavenCentral()
56
google()
6-
jcenter()
7-
87
}
98
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.5.3'
9+
classpath 'com.android.tools.build:gradle:7.0.3'
1110

1211
// NOTE: Do not place your application dependencies here; they belong
1312
// in the individual module build.gradle files
@@ -16,8 +15,8 @@ buildscript {
1615

1716
allprojects {
1817
repositories {
18+
mavenCentral()
1919
google()
20-
jcenter()
2120

2221
}
2322
}

flic2lib-android/build.gradle

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
plugins {
2-
id "com.jfrog.bintray" version "1.8.4"
32
id "maven-publish"
43
}
54

65
apply plugin: 'com.android.library'
7-
apply plugin: 'com.jfrog.bintray'
86

97
group = 'io.flic'
10-
version = '1.1.0'
8+
version = '1.3.0'
119

1210
android {
13-
compileSdkVersion 29
14-
buildToolsVersion "29.0.0"
15-
11+
compileSdkVersion 31
1612

1713
defaultConfig {
1814
minSdkVersion 19
19-
targetSdkVersion 29
20-
versionName '1.1.0'
15+
targetSdkVersion 31
16+
versionName '1.3.0'
17+
buildConfigField("String", "VERSION_NAME", "\"1.3.0\"")
2118

2219
consumerProguardFiles 'consumer-rules.pro'
2320
}
@@ -41,23 +38,4 @@ project.ext {
4138
mavProjectName = 'flic2lib-android'
4239
}
4340

44-
bintray {
45-
user = System.getenv("BINTRAY_USER")
46-
key = System.getenv("BINTRAY_KEY")
47-
publications = ['mavenPublish']
48-
pkg {
49-
userOrg = 'scl'
50-
repo = 'Flic'
51-
name = 'flic2lib-android'
52-
licenses = ['Libpng']
53-
vcsUrl = 'https://github.com/50ButtonsEach/flic2lib-android'
54-
55-
version {
56-
name = '1.1.0'
57-
released = new Date()
58-
vcsTag = '1.1.0'
59-
}
60-
}
61-
}
62-
6341
apply from: 'https://raw.githubusercontent.com/sky-uk/gradle-maven-plugin/1.0.4/gradle-mavenizer.gradle'
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="io.flic.flic2libandroid">
3-
<uses-permission android:name="android.permission.BLUETOOTH" />
4-
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
5-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
3+
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
4+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
5+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
6+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
7+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
68
<uses-permission android:name="android.permission.INTERNET"/>
79
</manifest>

0 commit comments

Comments
 (0)