Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BluetoothAdvertisements: updated graddle, migrated project to Android… #199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions BluetoothAdvertisements/Application/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.android.tools.build:gradle:4.0.1'
}
}

Expand All @@ -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'


}
Expand All @@ -36,16 +31,16 @@ dependencies {
// keep boilerplate and common code separate from
// the main sample code.
List<String> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.android.bluetoothadvertisements;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
Expand All @@ -11,6 +13,7 @@
import android.bluetooth.le.BluetoothLeAdvertiser;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
Expand All @@ -28,6 +31,7 @@ public class AdvertiserService extends Service {
private static final String TAG = AdvertiserService.class.getSimpleName();

private static final int FOREGROUND_NOTIFICATION_ID = 1;
private static final String NOTIFICATION_CHANNEL_ID = "advertiser_service_id";

/**
* A global variable to let AdvertiserFragment check if the Service is running without needing
Expand Down Expand Up @@ -152,15 +156,29 @@ private void startAdvertising() {
* Callers should call stopForeground(true) when background work is complete.
*/
private void goForeground() {
Notification.Builder builder;

if (Build.VERSION.SDK_INT >= 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions BluetoothAdvertisements/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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