From f7ef547332b6b8ec7876d46b76fccbf318e84d82 Mon Sep 17 00:00:00 2001 From: DmytroBatyuk Date: Thu, 10 Sep 2020 12:15:45 +0300 Subject: [PATCH] BluetoothAdvertisements: updated graddle, migrated project to AndroidX, updated notification and service regarding Android 10 rules --- .../Application/build.gradle | 25 +++++++--------- .../Application/src/main/AndroidManifest.xml | 5 ++++ .../AdvertiserFragment.java | 4 ++- .../AdvertiserService.java | 30 +++++++++++++++---- .../bluetoothadvertisements/MainActivity.java | 4 +-- .../ScannerFragment.java | 2 +- BluetoothAdvertisements/gradle.properties | 2 ++ .../gradle/wrapper/gradle-wrapper.properties | 3 +- 8 files changed, 49 insertions(+), 26 deletions(-) diff --git a/BluetoothAdvertisements/Application/build.gradle b/BluetoothAdvertisements/Application/build.gradle index ba01c35d..59ce9fcd 100644 --- a/BluetoothAdvertisements/Application/build.gradle +++ b/BluetoothAdvertisements/Application/build.gradle @@ -1,4 +1,3 @@ - buildscript { repositories { google() @@ -6,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.4.2' + classpath 'com.android.tools.build:gradle:4.0.1' } } @@ -20,14 +19,10 @@ repositories { dependencies { - implementation "com.android.support:support-v4:28.0.0" - implementation "com.android.support:support-v13:28.0.0" - implementation "com.android.support:cardview-v7:28.0.0" - implementation "com.android.support:appcompat-v7:28.0.0" - - - - + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation 'androidx.legacy:legacy-support-v13:1.0.0' + implementation 'androidx.cardview:cardview:1.0.0' + implementation 'androidx.appcompat:appcompat:1.2.0' } @@ -36,16 +31,16 @@ dependencies { // keep boilerplate and common code separate from // the main sample code. List dirs = [ - 'main', // main sample code; look here for the interesting stuff. - 'common', // components that are reused by multiple samples - 'template'] // boilerplate code that is generated by the sample template process + 'main', // main sample code; look here for the interesting stuff. + 'common', // components that are reused by multiple samples + 'template'] // boilerplate code that is generated by the sample template process android { - compileSdkVersion 28 + compileSdkVersion 29 defaultConfig { minSdkVersion 21 - targetSdkVersion 28 + targetSdkVersion 29 } compileOptions { diff --git a/BluetoothAdvertisements/Application/src/main/AndroidManifest.xml b/BluetoothAdvertisements/Application/src/main/AndroidManifest.xml index cd2a65e5..bfa3420b 100644 --- a/BluetoothAdvertisements/Application/src/main/AndroidManifest.xml +++ b/BluetoothAdvertisements/Application/src/main/AndroidManifest.xml @@ -22,6 +22,11 @@ + + + + + = Build.VERSION_CODES.O) { + ((NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel( + new NotificationChannel( + NOTIFICATION_CHANNEL_ID, + NOTIFICATION_CHANNEL_ID, + NotificationManager.IMPORTANCE_DEFAULT + )); + builder = new Notification.Builder(this, NOTIFICATION_CHANNEL_ID); + } else { + builder = new Notification.Builder(this); + } Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); - Notification n = new Notification.Builder(this) - .setContentTitle("Advertising device via Bluetooth") - .setContentText("This device is discoverable to others nearby.") - .setSmallIcon(R.drawable.ic_launcher) - .setContentIntent(pendingIntent) - .build(); + + Notification n = builder + .setContentTitle("Advertising device via Bluetooth") + .setContentText("This device is discoverable to others nearby.") + .setSmallIcon(R.drawable.ic_launcher) + .setContentIntent(pendingIntent) + .build(); startForeground(FOREGROUND_NOTIFICATION_ID, n); } diff --git a/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/MainActivity.java b/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/MainActivity.java index 7ea38916..cf533896 100644 --- a/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/MainActivity.java +++ b/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/MainActivity.java @@ -21,8 +21,8 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.support.v4.app.FragmentActivity; -import android.support.v4.app.FragmentTransaction; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentTransaction; import android.widget.TextView; import android.widget.Toast; diff --git a/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/ScannerFragment.java b/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/ScannerFragment.java index 4f5c2aa5..2d20afd9 100644 --- a/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/ScannerFragment.java +++ b/BluetoothAdvertisements/Application/src/main/java/com/example/android/bluetoothadvertisements/ScannerFragment.java @@ -24,7 +24,7 @@ import android.bluetooth.le.ScanSettings; import android.os.Bundle; import android.os.Handler; -import android.support.v4.app.ListFragment; +import androidx.fragment.app.ListFragment; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; diff --git a/BluetoothAdvertisements/gradle.properties b/BluetoothAdvertisements/gradle.properties index 0bc4294e..59169ec5 100644 --- a/BluetoothAdvertisements/gradle.properties +++ b/BluetoothAdvertisements/gradle.properties @@ -18,3 +18,5 @@ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true +android.enableJetifier=true +android.useAndroidX=true \ No newline at end of file diff --git a/BluetoothAdvertisements/gradle/wrapper/gradle-wrapper.properties b/BluetoothAdvertisements/gradle/wrapper/gradle-wrapper.properties index c4486d47..fe3bbccb 100644 --- a/BluetoothAdvertisements/gradle/wrapper/gradle-wrapper.properties +++ b/BluetoothAdvertisements/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Wed Sep 09 18:21:20 EEST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip