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

Fix crashes and deprecations for Android 12/Gradle 8 #673

Open
wants to merge 1 commit into
base: master
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
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
5 changes: 3 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,9 @@ 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 = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M
? PendingIntent.getBroadcast(context, 0, refresh, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE)
: 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,9 @@ 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);
return android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M
? PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE)
: 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,10 @@ 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 = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M
? PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)
: 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,9 @@ 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 = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M
? PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)
: 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,9 @@ 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 = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M
? PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)
: 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,9 @@ 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 = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M
? PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)
: 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