Skip to content

Commit 6f57144

Browse files
author
Lalumo Admin
committed
fix: add foreground service type for Android 12+ compatibility
set Version to 1.4.1
1 parent 6b22edf commit 6f57144

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ http://forum.xda-developers.com/showthread.php?t=2718943
1111

1212
Development
1313
===========
14-
If you want to help developing the app, this will work as an example (tested on Ubuntu 19.10):
14+
If you want to help developing the app, this will work as an example (tested on Ubuntu 24.04):
1515

1616
- Install and open Android Studio
1717
- [Created a virtual AVD Device](https://developer.android.com/studio/run/managing-avds#createavd)

identiconizer/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.germainz.identiconizer"
1111
minSdk 14
1212
targetSdk 34
13-
versionCode 11
14-
versionName "1.4"
13+
versionCode 12
14+
versionName "1.4.1"
1515
vectorDrawables.useSupportLibrary = true
1616
}
1717

identiconizer/src/main/AndroidManifest.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
66
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
77
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
8+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
89

910
<application
1011
android:icon="@mipmap/ic_launcher"
@@ -31,10 +32,12 @@
3132
android:exported="false" />
3233
<service
3334
android:name=".services.IdenticonCreationService"
34-
android:exported="false" />
35+
android:exported="false"
36+
android:foregroundServiceType="dataSync" />
3537
<service
3638
android:name=".services.IdenticonRemovalService"
37-
android:exported="false" />
39+
android:exported="false"
40+
android:foregroundServiceType="dataSync" />
3841

3942
<meta-data
4043
android:name="xposedmodule"

identiconizer/src/main/java/com/germainz/identiconizer/services/IdenticonCreationService.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.app.NotificationChannel;
2323
import android.app.NotificationManager;
2424
import android.app.PendingIntent;
25+
import android.content.pm.ServiceInfo;
2526
import android.content.ContentResolver;
2627
import android.content.ContentValues;
2728
import android.content.Context;
@@ -59,7 +60,12 @@ public IdenticonCreationService() {
5960

6061
@Override
6162
protected void onHandleIntent(Intent intent) {
62-
startForeground(SERVICE_NOTIFICATION_ID, createNotification());
63+
// For Android 12+ (API 31+), foreground service type must be specified
64+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
65+
startForeground(SERVICE_NOTIFICATION_ID, createNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
66+
} else {
67+
startForeground(SERVICE_NOTIFICATION_ID, createNotification());
68+
}
6369
// If a predefined contacts list is provided, use it directly.
6470
// contactsList is set when this service is started from ContactsListActivity.
6571
if (intent.hasExtra("contactsList")) {

identiconizer/src/main/java/com/germainz/identiconizer/services/IdenticonRemovalService.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import android.app.IntentService;
2121
import android.app.Notification;
22+
import android.content.pm.ServiceInfo;
2223
import android.app.NotificationChannel;
2324
import android.app.NotificationManager;
2425
import android.app.PendingIntent;
@@ -55,7 +56,12 @@ public IdenticonRemovalService() {
5556

5657
@Override
5758
protected void onHandleIntent(Intent intent) {
58-
startForeground(SERVICE_NOTIFICATION_ID, createNotification());
59+
// For Android 12+ (API 31+), foreground service type must be specified
60+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
61+
startForeground(SERVICE_NOTIFICATION_ID, createNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
62+
} else {
63+
startForeground(SERVICE_NOTIFICATION_ID, createNotification());
64+
}
5965
// If a predefined contacts list is provided, use it directly.
6066
// contactsList is set when this service is started from ContactsListActivity.
6167
if (intent.hasExtra("contactsList")) {

0 commit comments

Comments
 (0)