Skip to content

Commit 707d279

Browse files
authored
Merge pull request #33 from SmartDeviceLink-Examples/5.7.0_updates
Update app for Android 14 and SDL Java Suite 5.7.0
2 parents 3fddfdf + 94c32eb commit 707d279

File tree

6 files changed

+30
-16
lines changed

6 files changed

+30
-16
lines changed

MobileWeather/app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 33
4+
compileSdkVersion 34
55
defaultConfig {
66
applicationId "com.sdl.mobileweather"
77
minSdkVersion 16
8-
targetSdkVersion 33
9-
versionCode 27
8+
targetSdkVersion 34
9+
versionCode 28
1010
versionName "1.7.15"
1111
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
1212
}
@@ -37,7 +37,7 @@ dependencies {
3737
testImplementation 'junit:junit:4.12'
3838
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
3939
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
40-
implementation 'com.smartdevicelink:sdl_android:5.6.0'
40+
implementation 'com.smartdevicelink:sdl_android:5.7.0'
4141
implementation 'net.hockeyapp.android:HockeySDK:5.1.0'
4242
implementation 'com.google.android.gms:play-services-location:16.0.0'
4343
}

MobileWeather/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
tools:targetApi="31"/>
1111
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"
1212
tools:targetApi="33"/>
13+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE"
14+
tools:targetApi="34"/>
1315
<!-- Required for weather data -->
1416
<uses-permission android:name="android.permission.INTERNET" />
1517
<!-- Required to check if WiFi is enabled -->

MobileWeather/app/src/main/java/com/sdl/mobileweather/smartdevicelink/SdlReceiver.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.smartdevicelink.transport.SdlBroadcastReceiver;
1111
import com.smartdevicelink.transport.SdlRouterService;
1212
import com.smartdevicelink.transport.TransportConstants;
13+
import com.smartdevicelink.util.AndroidTools;
1314

1415
public class SdlReceiver extends SdlBroadcastReceiver {
1516

@@ -48,6 +49,11 @@ public void onSdlEnabled(Context context, Intent intent) {
4849

4950
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
5051
if (intent.getParcelableExtra(TransportConstants.PENDING_INTENT_EXTRA) != null) {
52+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
53+
if (!AndroidTools.hasForegroundServiceTypePermission(context)) {
54+
return;
55+
}
56+
}
5157
PendingIntent pendingIntent = (PendingIntent) intent.getParcelableExtra(TransportConstants.PENDING_INTENT_EXTRA);
5258
try {
5359
//Here we are allowing the RouterService that is in the Foreground to start the SdlService on our behalf

MobileWeather/app/src/main/java/com/sdl/mobileweather/smartdevicelink/SdlService.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -556,16 +556,22 @@ private void checkSoftButtonStates() {
556556
@SuppressLint("NewApi")
557557
private void enterForeground() {
558558
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
559-
NotificationChannel channel = new NotificationChannel("MobileWeather", "SmartDeviceLink", NotificationManager.IMPORTANCE_DEFAULT);
560-
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
561-
if (notificationManager != null) {
562-
notificationManager.createNotificationChannel(channel);
563-
Notification serviceNotification = new Notification.Builder(this, channel.getId())
564-
.setContentTitle("SmartDeviceLink")
565-
.setSmallIcon(R.drawable.ic_sdl)
566-
.setTicker("SmartDeviceLink")
567-
.build();
568-
startForeground(FOREGROUND_SERVICE_ID, serviceNotification);
559+
try {
560+
NotificationChannel channel = new NotificationChannel("MobileWeather", "SmartDeviceLink", NotificationManager.IMPORTANCE_DEFAULT);
561+
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
562+
if (notificationManager != null) {
563+
notificationManager.createNotificationChannel(channel);
564+
Notification serviceNotification = new Notification.Builder(this, channel.getId())
565+
.setContentTitle("SmartDeviceLink")
566+
.setSmallIcon(R.drawable.ic_sdl)
567+
.setTicker("SmartDeviceLink")
568+
.build();
569+
startForeground(FOREGROUND_SERVICE_ID, serviceNotification);
570+
}
571+
} catch (Exception e) {
572+
// This should only occur when using TCP connections on Android 14+ due to needing
573+
// specific connected devices for permissions regarding ForegroundServiceType
574+
// ConnectedDevice where a TCP connection doesn't apply
569575
}
570576
}
571577
}

MobileWeather/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
mavenCentral()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:4.1.1'
10+
classpath 'com.android.tools.build:gradle:7.4.2'
1111

1212

1313
// NOTE: Do not place your application dependencies here; they belong

MobileWeather/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip

0 commit comments

Comments
 (0)