处理来自“图书馆”模块的城市飞艇通知

我正在开发一个库模块,我需要处理库端的推送通知。我正在使用UrbanAirship作为通知提供商。

我有一个处理所有API调用的类,我需要在这些API调用之间接收推送通知。根据以下代码片段,用户注册应用程序必须接收到推送后,并使用该推送令牌来调用下一个API调用。这必须是一个连锁过程。

我的问题是如何在我的API处理类中获取推送内容并继续下一个API调用?

public void registerUser(final String registrationQrKey,String userObj,final 
sampleSDK.ResponseCallback<Boolean> response) {
            RESTAPIService restApi = RestAPIClient.getclient().create(RESTAPIService.class);
            restApi.TokenRequest(bTokenTemp,certi).enqueue(new Callback<TokenResponse>() {
                public void onResponse(Call<TokenResponse> call,Response<TokenResponse> apiResponse) {
                    if (apiResponse.isSuccessful()){
                        //Verify signature and the payload
                       **String pushToken = "Must receive from the push notification"**
                        userValidation(pushToken,new ResCallBack< String >(){
                            @Override
                            public void success(java.lang.String res) {
                                response.onSuccess(true);
                            }
                            @Override
                            public void failure(java.lang.String e) {
                                Log.d("ERROR CODE : ",e);
                                response.onFailure( " Error Code :  " + e);
                            }
                        });
                    }
                }
                public void onFailure(Call<TokenResponse> call,Throwable t) {
                    Log.d("ERROR CODE : ",t.getMessage());
                    response.onFailure( " Error Code :  " + t.getMessage());
                }
            });
        }).execute(context);
}

下面是“城市飞艇”服务类,能够接收推送通知。

public class SampleAutoPilot extends Autopilot {
    private static final String FIRST_RUN_KEY = "first_run";
    @Override
    public void onAirshipReady(@NonNull UAirship airship) {
        airship.getPushManager().setUserNotificationsEnabled(true);

        // Push listener
        airship.getPushManager().addPushListener((message,notificationPosted) -> {
            Log.i("","Received push message. Alert: " + message.getalert() + ". posted notification: " + notificationPosted);
        });

        // Notification listener
        airship.getPushManager().setNotificationListener(new NotificationListener() {
            @Override
            public void onNotificationPosted(@NonNull NotificationInfo notificationInfo) {
                Log.i("","Notification posted. Alert: " + notificationInfo.getMessage().getalert() + ". NotificationId: " + notificationInfo.getNotificationId());
            }

            @Override
            public boolean onNotificationOpened(@NonNull NotificationInfo notificationInfo) {
                Log.i("","Notification opened. Alert: " + notificationInfo.getMessage().getalert() + ". NotificationId: " + notificationInfo.getNotificationId());
                // Return false here to allow Airship to auto launch the launcher activity
                new NotificationDelegator(notificationInfo.getMessage().getalert());
                return false;
            }

            @Override
            public boolean onNotificationForegroundaction(@NonNull NotificationInfo notificationInfo,@NonNull NotificationactionButtonInfo actionButtonInfo) {
                Log.i("","Notification foreground action. Button ID: " + actionButtonInfo.getButtonId() + ". NotificationId: " + notificationInfo.getNotificationId());
                return false;
            }

            @Override
            public void onNotificationBackgroundaction(@NonNull NotificationInfo notificationInfo,"Notification background action. Button ID: " + actionButtonInfo.getButtonId() + ". NotificationId: " + notificationInfo.getNotificationId());
            }

            @Override
            public void onNotificationDismissed(@NonNull NotificationInfo notificationInfo) {
                Log.i("","Notification dismissed. Alert: " + notificationInfo.getMessage().getalert() + ". Notification ID: " + notificationInfo.getNotificationId());
            }
        });
    }

    @Override
    public AirshipConfigOptions createAirshipConfigOptions(@NonNull Context context) {
        return super.createAirshipConfigOptions(context);
    }
}
Ian701 回答:处理来自“图书馆”模块的城市飞艇通知

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2701234.html

大家都在问