Skip to content

Commit

Permalink
Fix crashes and deprecations for Android 12/Gradle 8
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamNiederer committed Mar 29, 2022
1 parent 917a183 commit 6db9e77
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ apply plugin: 'com.android.application'
def lifecycleVersion = '2.2.0'

android {
compileSdkVersion 29
compileSdkVersion 32
defaultConfig {
applicationId "cz.martykan.forecastie"
minSdkVersion 15
targetSdkVersion 29
targetSdkVersion 32
versionCode 74
versionName "1.22.1"
}
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
android:supportsRtl="true">

<activity
android:exported="true"
android:name=".activities.SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
Expand Down Expand Up @@ -54,7 +55,7 @@

<!-- Receivers -->

<receiver android:name=".widgets.ExtensiveWidgetProvider" android:label="@string/widget_label_extensive">
<receiver android:exported="true" android:name=".widgets.ExtensiveWidgetProvider" android:label="@string/widget_label_extensive">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -64,7 +65,7 @@
android:resource="@xml/extensive_widget" />
</receiver>

<receiver android:name=".widgets.TimeWidgetProvider" android:label="@string/widget_label_time">
<receiver android:exported="true" android:name=".widgets.TimeWidgetProvider" android:label="@string/widget_label_time">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -74,7 +75,7 @@
android:resource="@xml/time_widget" />
</receiver>

<receiver android:name=".widgets.SimpleWidgetProvider" android:label="@string/widget_label_simple">
<receiver android:exported="true" android:name=".widgets.SimpleWidgetProvider" android:label="@string/widget_label_simple">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -84,7 +85,7 @@
android:resource="@xml/simple_widget" />
</receiver>

<receiver android:name=".widgets.ClassicTimeWidgetProvider" android:label="@string/widget_label_classic">
<receiver android:exported="true" android:name=".widgets.ClassicTimeWidgetProvider" android:label="@string/widget_label_classic">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -94,7 +95,7 @@
android:resource="@xml/time_widget_classic" />
</receiver>

<receiver android:name=".AlarmReceiver">
<receiver android:exported="true" android:name=".AlarmReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/cz/martykan/forecastie/AlarmReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,14 @@ public static void setRecurringAlarm(Context context) {
String intervalPref = PreferenceManager.getDefaultSharedPreferences(context)
.getString("refreshInterval", "1");
Intent refresh = new Intent(context, AlarmReceiver.class);
PendingIntent recurringRefresh = PendingIntent.getBroadcast(context,
0, refresh, PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent recurringRefresh = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
recurringRefresh = PendingIntent.getBroadcast(context,
0, refresh, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else {
recurringRefresh = PendingIntent.getBroadcast(context,
0, refresh, PendingIntent.FLAG_CANCEL_CURRENT);
}
AlarmManager alarms = (AlarmManager) context.getSystemService(
Context.ALARM_SERVICE);
long intervalMillis = intervalMillisForRecurringAlarm(intervalPref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ protected void cancelUpdate(Context context) {
protected PendingIntent getTimeIntent(Context context) {
Intent intent = new Intent(context, this.getClass());
intent.setAction(ACTION_UPDATE_TIME);
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else {
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}
}

protected String getFormattedTemperature(Weather weather, Context context, SharedPreferences sp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
setTheme(context, remoteViews);

Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else {
pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
remoteViews.setOnClickPendingIntent(R.id.widgetButtonRefresh, pendingIntent);

SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
setTheme(context, remoteViews);

Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else {
pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
remoteViews.setOnClickPendingIntent(R.id.widgetButtonRefresh, pendingIntent);

SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
setTheme(context, remoteViews);

Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else {
pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
remoteViews.setOnClickPendingIntent(R.id.widgetButtonRefresh, pendingIntent);

SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
setTheme(context, remoteViews);

Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else {
pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
remoteViews.setOnClickPendingIntent(R.id.widgetButtonRefresh, pendingIntent);

SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.android.tools.build:gradle:7.1.2'
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip

0 comments on commit 6db9e77

Please sign in to comment.