Обработка уведомлений городского дирижабля из библиотечного модуля - PullRequest
0 голосов
/ 28 января 2020

Я занимаюсь разработкой библиотечного модуля, и мне нужно обработать уведомление pu sh со стороны библиотеки. Я использую UrbanAirship в качестве поставщика уведомлений.

У меня есть класс, который обрабатывает все мои вызовы API, и мне нужно получать уведомления pu sh между этими вызовами API. В соответствии с приведенным ниже фрагментом кода приложение регистрации пользователя должно получить pu sh и использовать этот токен pu sh для вызова следующего вызова API. Это должен быть цепной процесс.

Мой вопрос заключается в том, как получить содержимое pu sh в моем классе обработки 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);
}

Ниже приведен класс обслуживания Urban Airship и возможность его получения. pu sh уведомления.

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, @NonNull NotificationActionButtonInfo actionButtonInfo) {
                Log.i("", "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);
    }
}
...