Skip to content

Commit ae5af61

Browse files
authored
Merge pull request #14 from PAXSTORE/hotfix/v10.0.2
Hotfix/v10.0.2
2 parents 672b7a7 + a963264 commit ae5af61

7 files changed

Lines changed: 73 additions & 36 deletions

File tree

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
jcenter()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:8.0.2'
9+
classpath 'com.android.tools.build:gradle:8.3.2'
1010
//https://github.com/novoda/bintray-release check latest version of novoda
1111
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1212

@@ -21,7 +21,8 @@ allprojects {
2121
google()
2222
jcenter()
2323
maven { url 'https://jitpack.io' }
24-
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
24+
maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
25+
2526
}
2627
tasks.withType(Javadoc) {
2728
options{

demo/build.gradle

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

33
android {
4-
compileSdkVersion 30
4+
compileSdkVersion 34
55
defaultConfig {
66
applicationId "com.pax.android.demoapp.cloudmsg"
77
minSdkVersion 19
8-
targetSdkVersion 30
8+
targetSdkVersion 34
99
versionCode 900
1010
versionName "10.0.0"
1111
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ org.gradle.jvmargs=-Xmx1024m
2121
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
2222
# org.gradle.parallel=true
2323

24-
version=10.0.0
24+
version=10.0.2

sdk/build.gradle

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
apply plugin: 'com.android.library'
22

3-
3+
java {
4+
toolchain {
5+
// It is strongly recommended to set it to Java 8 or Java 11 for the best compatibility.
6+
languageVersion = JavaLanguageVersion.of(17)
7+
}
8+
}
49
android {
5-
compileSdkVersion 29
10+
compileSdkVersion 34
611

712
defaultConfig {
813
minSdkVersion 19
@@ -29,14 +34,19 @@ android {
2934
exclude 'META-INF/LICENSE'
3035
}
3136
namespace 'com.pax.market.android.app.sdk.msg'
37+
compileOptions {
38+
//It is strongly recommended to set it to Java 8 or Java 11 for the best compatibility.
39+
sourceCompatibility JavaVersion.VERSION_1_8
40+
targetCompatibility JavaVersion.VERSION_1_8
41+
}
3242
}
3343

3444
dependencies {
3545
api fileTree(include: ['*.jar'], dir: 'libs')
3646
implementation 'com.google.code.gson:gson:2.9.0'
3747
implementation 'org.slf4j:slf4j-api:1.7.12'
3848

39-
compileOnly 'com.whatspos.sdk:paxstore-3rd-app-java-sdk:10.0.0'
49+
implementation 'com.whatspos.sdk:paxstore-3rd-app-java-sdk:10.0.1'
4050

4151
}
4252

sdk/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
22

3-
3+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
4+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
5+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
46
<application>
57

68
<meta-data
@@ -10,6 +12,7 @@
1012

1113
<service android:name="com.pax.market.android.app.sdk.msg.service.CloudMessageService"
1214
android:permission="com.market.android.app.sdk.CLOUD_MSG"
15+
android:foregroundServiceType="dataSync"
1316
android:exported="true">
1417
<intent-filter>
1518
<action android:name="com.paxstore.mpush.CLOUD_MESSAGE_RECEIVED"/>

sdk/src/main/java/com/pax/market/android/app/sdk/msg/service/CloudMessageService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public CloudMessageService() {
5555

5656
@Override
5757
public int onStartCommand(Intent intent, int flags, int startId) {
58-
NotificationUtils.showForeGround(this, "Cloud message");
58+
NotificationUtils.showForeGround(this, "Cloud message", NotificationUtils.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
5959
return super.onStartCommand(intent, flags, startId);
6060
}
6161

sdk/src/main/java/com/pax/market/android/app/sdk/msg/utils/NotificationUtils.java

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,67 @@
88
import android.app.NotificationManager;
99
import android.app.Service;
1010
import android.content.Context;
11+
import android.content.pm.ServiceInfo;
12+
import android.os.Build;
1113

1214
import com.pax.market.android.app.sdk.msg.R;
1315

1416

1517
public class NotificationUtils {
1618
private static final int NOTIFICATION_ID = 1002;
1719

18-
private static final String LIBRARY_PACKAGE_NAME = "com.pax.market.android.app.sdk.msg";
20+
public static final int FOREGROUND_SERVICE_TYPE_DATA_SYNC = 1 << 0;
1921

22+
private static final String LIBRARY_PACKAGE_NAME = "com.pax.market.android.app.sdk.msg";
2023
/**
21-
*
22-
* @param service
23-
* @param smallIcon
24-
* @param content
24+
* @deprecated This method is deprecated because it does not support the mandatory
25+
* foreground service types required by Android 14 (API 34).
26+
* <b>Migration Guide:</b><br>
27+
* Please migrate to {@link #showForeGround(Service, int, String, int)} to explicitly
28+
* provide the correct service type for your business logic.
2529
*/
2630
public static void showForeGround(Service service, int smallIcon, String content) {
27-
NotificationChannel mChannel = null;
28-
NotificationManager notificationManager = (NotificationManager) service.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
31+
showForeGround(service, smallIcon, content, 0);
32+
}
2933

30-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
31-
mChannel = new NotificationChannel(LIBRARY_PACKAGE_NAME, service.getApplicationContext().getString(R.string.app_name), NotificationManager.IMPORTANCE_NONE);
32-
mChannel.setSound(null, null);
33-
mChannel.enableVibration(false);
34-
notificationManager.createNotificationChannel(mChannel);
34+
/**
35+
* @deprecated This method is deprecated because it does not support the mandatory
36+
* foreground service types required by Android 14 (API 34).
37+
* <b>Migration Guide:</b><br>
38+
* Please migrate to {@link #showForeGround(Service, String, int)} to explicitly
39+
* provide the correct service type for your business logic.
40+
*/
41+
@Deprecated
42+
public static void showForeGround(Service service, String content) {
43+
showForeGround(service, content, 0);
44+
}
3545

36-
Notification.Builder builder = new Notification.Builder(service.getApplicationContext(), LIBRARY_PACKAGE_NAME);
37-
builder.setContentText(content);
38-
builder.setSmallIcon(smallIcon);
39-
builder.setAutoCancel(true);
40-
builder.setShowWhen(true);
4146

42-
// 这里两个通知使用同一个id且必须按照这个顺序后调用startForeground
43-
service.startForeground(NOTIFICATION_ID, builder.build());
44-
}
47+
/**
48+
* Updated method to support Android 14 foreground service types.
49+
*
50+
* @param service The Service instance.
51+
* @param content Content to display in the notification.
52+
* @param foregroundServiceType The type(s) of foreground service,
53+
* e.g., {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_DATA_SYNC}.
54+
*/
55+
public static void showForeGround(Service service, String content, int foregroundServiceType) {
56+
showForeGround(service, PreferencesUtils.getInt(service, SP_SMALL_LOGO_ICON, R.drawable.ic_notificaiton), content, foregroundServiceType);
57+
4558
}
4659

60+
4761
/**
62+
* Updated method to support Android 14 foreground service types.
4863
*
49-
* @param service
50-
* @param content
64+
* @param service The Service instance.
65+
* @param content Content to display in the notification.
66+
* @param smallIcon The icon display in the notification.
67+
* @param foregroundServiceType The type(s) of foreground service,
68+
* e.g., {@link ServiceInfo#FOREGROUND_SERVICE_TYPE_DATA_SYNC}.
5169
*/
52-
public static void showForeGround(Service service, String content) {
70+
public static void showForeGround(Service service, int smallIcon, String content, int foregroundServiceType) {
71+
5372
NotificationChannel mChannel = null;
5473
NotificationManager notificationManager = (NotificationManager) service.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
5574

@@ -61,12 +80,16 @@ public static void showForeGround(Service service, String content) {
6180

6281
Notification.Builder builder = new Notification.Builder(service.getApplicationContext(), LIBRARY_PACKAGE_NAME);
6382
builder.setContentText(content);
64-
builder.setSmallIcon(PreferencesUtils.getInt(service, SP_SMALL_LOGO_ICON, R.drawable.ic_notificaiton));
83+
builder.setSmallIcon(smallIcon);
6584
builder.setAutoCancel(true);
6685
builder.setShowWhen(true);
6786

68-
// 这里两个通知使用同一个id且必须按照这个顺序后调用startForeground
69-
service.startForeground(NOTIFICATION_ID, builder.build());
87+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { // API 34
88+
service.startForeground(NOTIFICATION_ID, builder.build(), foregroundServiceType);
89+
} else {
90+
service.startForeground(NOTIFICATION_ID, builder.build());
91+
}
7092
}
7193
}
94+
7295
}

0 commit comments

Comments
 (0)