我们使用的是Smartech SDK 3.0.1,我已经集成了SDK方法来设置FCM令牌,但当我看到SDK日志时,我得到的pushToken和oldPushToken值为空。在我的日志中,我可以看到我的代币存在。请帮我解决这个问题。
{
"advertiserId": "",
"eventId": "99",
"pushTokens": [
{
"gwSource": 1,
"pushToken": "",
"pushTokenOld": ""
}
],
"guid": "XXXX-XXXX-XXXX-XXXX",
"carrier": "",
"deviceHeight": "1280",
"appId": "XXXX-XXXX-XXXX-XXXX",
"deviceLocale": "en",
"radio": "UNKNOWN",
"deviceWidth": "800",
"deviceMake": "lenovo",
"vendorId": "",
"countryCode": "",
"appVersion": "1.0",
"sdkVersion": "3.0.1",
"appBuild": "1",
"useAdvId": false,
"osName": "android",
"pushTokenOld": "",
"eventTime": "1604323968134",
"osVersion": "7.1.1",
"deviceModel": "lenovo tb-x304l",
"appBundleId": "com.mysampleapp",
"pushToken": "",
"eventName": "device_common_data",
"bod": 3602
}
您可能错过了捕获令牌并将其传递给SDK。在应用程序类中使用以下解决方法。这个片段将从Firebase获取生成的FCM令牌,并将其设置为SDK。
private void setFCMPushToken(final Context context) {
try {
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (task.isSuccessful() && task.getResult() != null) {
Smartech smartech = Smartech.getInstance(new WeakReference<>(context));
String fcmToken = task.getResult().getToken();
String currentToken = smartech.getDevicePushToken();
Log.i("TOKEN", "FCM Instance Id Token: " + fcmToken);
Log.i("TOKEN", "Current FCM Token: " + currentToken);
if (TextUtils.isEmpty(currentToken)) {
smartech.setDevicePushToken(fcmToken);
Log.i("TOKEN", "New token set: " + fcmToken);
} else if (!currentToken.equals(fcmToken)) {
smartech.setDevicePushToken(fcmToken);
Log.i("TOKEN", "New token set: " + fcmToken);
} else {
Log.i("TOKEN", "Both tokens are same.");
}
}
}
});
} catch (Exception e) {
e.printStackTrace();
Log.e("TOKEN", "Failed to set token.");
}
}