Skip to content

Commit ddd815e

Browse files
authored
Merge pull request #170 from jwfing/master
upgrade fcm/hms dependencies
2 parents 2142a66 + 4d22fcd commit ddd815e

File tree

14 files changed

+63
-105
lines changed

14 files changed

+63
-105
lines changed

android-sdk/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buildscript {
1010
}
1111
dependencies {
1212
classpath 'com.android.tools.build:gradle:3.6.3'
13-
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
13+
classpath 'com.huawei.agconnect:agcp:1.4.2.300'
1414

1515
// NOTE: Do not place your application dependencies here; they belong
1616
// in the individual module build.gradle files
@@ -30,7 +30,7 @@ allprojects {
3030
}
3131

3232
ext {
33-
sdkVersion = "7.2.4"
33+
sdkVersion = "7.2.5"
3434
supportLibVersion = "26.1.0"
3535
converterVersion = "2.1.0"
3636
rxandroidVersion = "2.1.1"

android-sdk/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ org.gradle.jvmargs=-Xmx1536m
1515
# This option should only be used with decoupled projects. More details, visit
1616
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1717
# org.gradle.parallel=true
18-
VERSION_NAME=7.2.4
18+
VERSION_NAME=7.2.5
1919
VERSION_CODE=2695
2020
GROUP=cn.leancloud
2121

android-sdk/leancloud-fcm/build.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ android {
55
buildToolsVersion "28.0.3"
66

77
defaultConfig {
8-
minSdkVersion 14
8+
minSdkVersion 16
99
targetSdkVersion 26
1010
versionCode 1
1111
versionName "1.0"
@@ -59,10 +59,12 @@ dependencies {
5959

6060
implementation("cn.leancloud:realtime-core:${rootProject.ext.sdkVersion}")
6161

62-
implementation 'com.google.firebase:firebase-core:15.0.2'
63-
implementation 'com.google.firebase:firebase-iid:15.0.2'
64-
implementation 'com.google.firebase:firebase-messaging:15.0.2'
65-
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
62+
// Import the BoM for the Firebase platform
63+
implementation platform('com.google.firebase:firebase-bom:27.0.0')
64+
65+
// Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
66+
// When using the BoM, you don't specify versions in Firebase library dependencies
67+
implementation 'com.google.firebase:firebase-messaging'
6668

6769
implementation 'androidx.appcompat:appcompat:1.0.0'
6870
testImplementation 'junit:junit:4.12'

android-sdk/leancloud-fcm/src/main/java/cn/leancloud/AVFCMJobService.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

android-sdk/leancloud-fcm/src/main/java/cn/leancloud/AVFirebaseInstanceIDService.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

android-sdk/leancloud-fcm/src/main/java/cn/leancloud/AVFirebaseMessagingService.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package cn.leancloud;
22

3+
import cn.leancloud.callback.SaveCallback;
4+
import cn.leancloud.convertor.ObserverBuilder;
35
import cn.leancloud.json.JSON;
46
import cn.leancloud.json.JSONObject;
57

@@ -8,16 +10,17 @@
810

911
import java.util.Map;
1012

11-
import cn.leancloud.push.AVPushMessageListener;
1213
import cn.leancloud.push.AndroidNotificationManager;
1314
import cn.leancloud.utils.LogUtil;
15+
import cn.leancloud.utils.StringUtil;
1416

1517
/**
1618
* Created by fengjunwen on 2018/8/28.
1719
*/
1820

1921
public class AVFirebaseMessagingService extends FirebaseMessagingService {
2022
private final static AVLogger LOGGER = LogUtil.getLogger(AVFirebaseMessagingService.class);
23+
private final String VENDOR = "fcm";
2124

2225
/**
2326
* FCM 有两种消息:通知消息与数据消息。
@@ -62,6 +65,42 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
6265
}
6366
}
6467

68+
@Override
69+
public void onNewToken(String token) {
70+
LOGGER.d("refreshed token: " + token);
71+
72+
// If you want to send messages to this application instance or
73+
// manage this apps subscriptions on the server side, send the
74+
// FCM registration token to your app server.
75+
sendRegistrationToServer(token);
76+
}
77+
78+
private void sendRegistrationToServer(String refreshedToken) {
79+
if (StringUtil.isEmpty(refreshedToken)) {
80+
return;
81+
}
82+
AVInstallation installation = AVInstallation.getCurrentInstallation();
83+
if (!VENDOR.equals(installation.getString(AVInstallation.VENDOR))) {
84+
installation.put(AVInstallation.VENDOR, VENDOR);
85+
}
86+
if (!refreshedToken.equals(installation.getString(AVInstallation.REGISTRATION_ID))) {
87+
installation.put(AVInstallation.REGISTRATION_ID, refreshedToken);
88+
}
89+
installation.saveInBackground().subscribe(
90+
ObserverBuilder.buildSingleObserver(new SaveCallback() {
91+
@Override
92+
public void done(AVException e) {
93+
if (null != e) {
94+
LOGGER.e("failed to update installation.", e);
95+
} else {
96+
LOGGER.d("succeed to update installation.");
97+
}
98+
}
99+
}));
100+
101+
LOGGER.d("FCM registration success! registrationId=" + refreshedToken);
102+
}
103+
65104
@Override
66105
public void onDeletedMessages() {
67106
super.onDeletedMessages();

android-sdk/leancloud-search-sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<action android:name="android.intent.action.VIEW" />
1616
<category android:name="android.intent.category.DEFAULT" />
1717
<category android:name="android.intent.category.BROWSABLE" />
18-
<data android:scheme="cn.leancloud.qJnLgVRA9mnzVSw4Ho3HtIaI-gzGzoHsz" />
18+
<data android:scheme="cn.leancloud.qjnlgvra9mnzvsw4ho3htiai-gzgzohsz" />
1919
<data android:host="leancloud" />
2020
<data android:pathPrefix="/classes/Reply/" />
2121
</intent-filter>

android-sdk/leancloud-search/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion 28
4+
compileSdkVersion 29
55
buildToolsVersion "28.0.3"
66

77

android-sdk/mixpush-hms/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ apply plugin: 'com.android.library'
22
apply plugin: 'com.huawei.agconnect'
33

44
android {
5-
compileSdkVersion 28
6-
buildToolsVersion "28.0.3"
5+
compileSdkVersion 29
6+
buildToolsVersion "29.0.3"
77

88
defaultConfig {
9-
minSdkVersion 17
10-
targetSdkVersion 26
9+
minSdkVersion 19
10+
targetSdkVersion 29
1111
versionCode 1
1212
versionName "1.0"
1313

@@ -61,7 +61,7 @@ dependencies {
6161

6262
implementation("cn.leancloud:realtime-core:${rootProject.ext.sdkVersion}")
6363

64-
implementation 'com.huawei.hms:push:4.0.2.300'
64+
implementation 'com.huawei.hms:push:5.1.1.301'
6565

6666
implementation 'androidx.appcompat:appcompat:1.0.0'
6767
testImplementation 'junit:junit:4.12'

android-sdk/mixpush-hms/src/main/java/cn/leancloud/AVHMSMessageService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public AVHMSMessageService() {
2626
*
2727
* @param remoteMessage
2828
*/
29+
@Override
2930
public void onMessageReceived(RemoteMessage remoteMessage) {
3031
try {
3132
AndroidNotificationManager androidNotificationManager = AndroidNotificationManager.getInstance();
@@ -46,9 +47,6 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
4647
}
4748
}
4849

49-
public void onDeletedMessages() {
50-
}
51-
5250
/**
5351
* 服务端更新token回调方法。
5452
* 参考文档:https://developer.huawei.com/consumer/cn/doc/development/HMS-References/push-HmsMessageService-cls#onMessageReceived
@@ -59,6 +57,7 @@ public void onDeletedMessages() {
5957
*
6058
* @param token
6159
*/
60+
@Override
6261
public void onNewToken(String token) {
6362
updateAVInstallation(token);
6463
}
@@ -67,6 +66,7 @@ public void onNewToken(String token) {
6766
* 申请token失败回调方法
6867
* @param exception
6968
*/
69+
@Override
7070
public void onTokenError(Exception exception) {
7171
LOGGER.w("failed to apply token. cause: " + exception.getMessage());
7272
}

0 commit comments

Comments
 (0)