Android/Java: 如何在新的OneSignal 4.0.0 中获取userId? (idsAvailable 已弃用,getPermissionSubscriptionState 不起作用)
Android/Java: How to get the userId in the new OneSignal 4.0.0? (idsAvailable is deprecated and getPermissionSubscriptionState doesn't work)
我通过添加 implementation 'com.onesignal:OneSignal:4.0.0'
升级了 onesignal,但现在有些代码不起作用。
已弃用的旧代码不再有效:
OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {
@Override
public void idsAvailable(String userId, String registrationId) {
}
});
无效的新代码:
String userId = OneSignal .getPermissionSubscriptionState().getSubscriptionStatus().getUserId();
有什么想法吗?
你必须安装这个:
https://documentation.onesignal.com/docs/android-sdk-setup
然后代码是这样的:
OSDeviceState deviceState = OneSignal.getDeviceState();
String userId = deviceState != null ? deviceState.getUserId() : null;
我通过添加 implementation 'com.onesignal:OneSignal:4.0.0'
升级了 onesignal,但现在有些代码不起作用。
已弃用的旧代码不再有效:
OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {
@Override
public void idsAvailable(String userId, String registrationId) {
}
});
无效的新代码:
String userId = OneSignal .getPermissionSubscriptionState().getSubscriptionStatus().getUserId();
有什么想法吗?
你必须安装这个:
https://documentation.onesignal.com/docs/android-sdk-setup
然后代码是这样的:
OSDeviceState deviceState = OneSignal.getDeviceState();
String userId = deviceState != null ? deviceState.getUserId() : null;