diff --git a/MobileWeather/app/build.gradle b/MobileWeather/app/build.gradle
index aa634be..2b1327a 100644
--- a/MobileWeather/app/build.gradle
+++ b/MobileWeather/app/build.gradle
@@ -1,11 +1,11 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 31
+ compileSdkVersion 33
defaultConfig {
applicationId "com.sdl.mobileweather"
minSdkVersion 16
- targetSdkVersion 31
+ targetSdkVersion 33
versionCode 27
versionName "1.7.15"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
@@ -37,7 +37,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
- implementation 'com.smartdevicelink:sdl_android:5.5.0'
+ implementation 'com.smartdevicelink:sdl_android:5.6.0'
implementation 'net.hockeyapp.android:HockeySDK:5.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
}
diff --git a/MobileWeather/app/src/main/AndroidManifest.xml b/MobileWeather/app/src/main/AndroidManifest.xml
index b3d20ca..28aadaf 100644
--- a/MobileWeather/app/src/main/AndroidManifest.xml
+++ b/MobileWeather/app/src/main/AndroidManifest.xml
@@ -8,6 +8,8 @@
+
diff --git a/MobileWeather/app/src/main/java/com/sdl/mobileweather/activity/MainActivity.java b/MobileWeather/app/src/main/java/com/sdl/mobileweather/activity/MainActivity.java
index 876f7b4..6657468 100755
--- a/MobileWeather/app/src/main/java/com/sdl/mobileweather/activity/MainActivity.java
+++ b/MobileWeather/app/src/main/java/com/sdl/mobileweather/activity/MainActivity.java
@@ -1,6 +1,5 @@
package com.sdl.mobileweather.activity;
-
import android.Manifest;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
@@ -14,6 +13,8 @@
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
+
+import androidx.annotation.NonNull;
import androidx.legacy.app.ActionBarDrawerToggle;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@@ -35,14 +36,15 @@
import com.sdl.mobileweather.fragments.ForecastFragment;
import com.sdl.mobileweather.smartdevicelink.SdlActivity;
import com.sdl.mobileweather.smartdevicelink.SdlApplication;
-import com.sdl.mobileweather.smartdevicelink.SdlReceiver;
+
+import java.util.ArrayList;
public class MainActivity extends SdlActivity implements ActionBar.TabListener {
private static final String SELECTED_NAVIGATION_ITEM = "selected_navigation_item";
private static final String APP_ID = "bf2c3a7bad6b0c79152f50cc42ba1ace";
- private static final int PERMISSIONS_REQUEST_CODE = 100;
+ private static final int PERMISSIONS_REQUEST_CODE = 200;
private Fragment mCurrentFragment;
private DrawerLayout mDrawerLayout;
@@ -137,14 +139,12 @@ else if ((getResources().getString(R.string.drawer_item_about)).equals(item)){
mDrawerList.setItemChecked(position, false);
mDrawerLayout.closeDrawer(mDrawerList);
}
-
-
-
+
private void checkForCrashes() {}
private void checkForUpdates() {}
- private boolean checkPermissions() {
+ private boolean hasPermissions() {
boolean permissionsGranted;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
@@ -159,17 +159,22 @@ private boolean checkPermissions() {
return permissionsGranted;
}
- private void requestPermissions() {
- String[] permissions;
+ private void requestPermission(String[] permissions, int REQUEST_CODE) {
+ ActivityCompat.requestPermissions(this, permissions, REQUEST_CODE);
+ }
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
- permissions = new String[]{Manifest.permission.BLUETOOTH_CONNECT, Manifest.permission.ACCESS_FINE_LOCATION};
+ private @NonNull String[] permissionsNeeded() {
+ ArrayList result = new ArrayList<>();
+ if (!hasBTPermission()) {
+ result.add(Manifest.permission.BLUETOOTH_CONNECT);
}
- else {
- permissions = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
+ if (!hasPNPermission()) {
+ result.add(Manifest.permission.POST_NOTIFICATIONS);
}
-
- ActivityCompat.requestPermissions(this, permissions, PERMISSIONS_REQUEST_CODE);
+ if (!hasLocation()) {
+ result.add(Manifest.permission.ACCESS_FINE_LOCATION);
+ }
+ return (result.toArray(new String[result.size()]));
}
@Override
@@ -238,13 +243,41 @@ protected void onStart() {
lbManager.registerReceiver(mHourlyForecastReceiver, new IntentFilter("com.sdl.mobileweather.HourlyForecast"));
// Ask for permissions
- if (!checkPermissions()) {
- requestPermissions();
- } else {
- startServices();
+ String[] permissionsNeeded = permissionsNeeded();
+ if (permissionsNeeded.length > 0) {
+ requestPermission(permissionsNeeded, PERMISSIONS_REQUEST_CODE);
+ for (String permission : permissionsNeeded) {
+ if (Manifest.permission.BLUETOOTH_CONNECT.equals(permission)) {
+ // We need to request BLUETOOTH_CONNECT permission to connect to SDL via Bluetooth
+ return;
+ }
+ }
}
+ startServices();
+ }
+
+ /**
+ * Boolean method that checks API level and check to see if we need to request BLUETOOTH_CONNECT permission
+ * @return false if we need to request BLUETOOTH_CONNECT permission
+ */
+ private boolean hasBTPermission() {
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? checkPermission(Manifest.permission.BLUETOOTH_CONNECT) : true;
+ }
+ /**
+ * Boolean method that checks API level and check to see if we need to request POST_NOTIFICATIONS permission
+ * @return false if we need to request POST_NOTIFICATIONS permission
+ */
+ private boolean hasPNPermission() {
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ? checkPermission(Manifest.permission.POST_NOTIFICATIONS) : true;
+ }
+ private boolean hasLocation() {
+ return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION);
+ }
+
+ private boolean checkPermission(String permission) {
+ return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(getApplicationContext(), permission);
}
private void startServices() {
@@ -400,11 +433,23 @@ public void onSaveInstanceState(Bundle outState) {
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == PERMISSIONS_REQUEST_CODE) {
- if (!checkPermissions()) {
+ if (!hasPermissions()) {
Toast.makeText(this, "The app cannot run without these permissions!", Toast.LENGTH_SHORT).show();
finish();
} else {
startServices();
+ if (grantResults.length > 0) {
+ for (int i = 0; i < grantResults.length; i++) {
+ if (permissions[i].equals(Manifest.permission.POST_NOTIFICATIONS)) {
+ boolean postNotificationGranted =
+ grantResults[i] == PackageManager.PERMISSION_GRANTED;
+ if (!postNotificationGranted) {
+ // User denied permission, Notifications for SDL will not appear
+ // on Android 13 devices.
+ }
+ }
+ }
+ }
}
}
}
diff --git a/MobileWeather/app/src/main/java/com/sdl/mobileweather/smartdevicelink/SdlService.java b/MobileWeather/app/src/main/java/com/sdl/mobileweather/smartdevicelink/SdlService.java
index 6c9d534..88e7ca9 100644
--- a/MobileWeather/app/src/main/java/com/sdl/mobileweather/smartdevicelink/SdlService.java
+++ b/MobileWeather/app/src/main/java/com/sdl/mobileweather/smartdevicelink/SdlService.java
@@ -80,7 +80,6 @@
import com.smartdevicelink.util.DebugTool;
import com.smartdevicelink.util.SystemInfo;
-
import com.smartdevicelink.util.SystemInfo;
import java.net.URL;
import java.text.SimpleDateFormat;
@@ -1029,18 +1028,7 @@ private void showWeatherConditions(boolean includeSpeak) {
getResources().getString(R.string.weather_conditions_speak),
title, temperature, humidity, windSpeed, speedUnitsFull);
}
- chunk.setText(speakString);
- chunk.setType(SpeechCapabilities.TEXT);
- chunks.add(chunk);
- final Speak speakRequest = new Speak();
- speakRequest.setTtsChunks(chunks);
- speakRequest.setCorrelationID(autoIncCorrId++);
- sdlManager.getScreenManager().commit(new CompletionListener() {
- @Override
- public void onComplete(boolean b) {
- sdlManager.sendRPC(speakRequest);
- }
- });
+ speak(speakString);
}
} else {
showNoConditionsAvail();
diff --git a/README.md b/README.md
index 5086e23..8a9ec7d 100644
--- a/README.md
+++ b/README.md
@@ -3,9 +3,8 @@
This tutorial is designed to show you how to include the SmartDeviceLink SDK in your app and to help you get your app’s features onto the vehicle’s infotainment head unit.
Please visit the [wiki](https://github.com/smartdevicelink/sdl_mobileweather_tutorial_android/wiki) of this repository to get the full tutorial.
-
-### Weather API Key
-
-1. Sign up and get your own [OpenWeather API Key](https://home.openweathermap.org/api_keys).
-2. Set the value of `API_KEY`in `OpenWeatherMapService.java` to your API key
+
+### Weather API Key
+
+1. Sign up and get your own [OpenWeather API Key](https://home.openweathermap.org/api_keys).
2. Set the value of `API_KEY`in `OpenWeatherMapService.java` to your API key