Geralt_Encore
Geralt_Encore

Reputation: 3771

Requesting new permissions fail handling

Login and asking permission works just fine. But there is one problem: I need to ask publish permission when user wants to share some date from my app. Here is my code:

ParseFacebookUtils.getSession().requestNewPublishPermissions(new NewPermissionsRequest((Activity) context,
            Arrays.asList(Permissions.Extended.PUBLISH_ACTIONS, Permissions.Extended.PUBLISH_STREAM))
        .setCallback(new StatusCallback() {
            @Override
            public void call(Session session, SessionState state, Exception exception) {
                if (!arePublishPermissionsEnabled(session)) {
                    inflow.setChecked(false);
                    facebook.setChecked(false);
                    twitter.setChecked(false);
                } 
            }
        }));

The problem is in handling situation when user canceled request or there is a loss of network connection. In this case I need to do some changes in my UI, but method call is calling only when session state is changed (e.g. granted new permissions) and I can't properly changed my UI. Is anyone faced such problem?

Upvotes: 0

Views: 361

Answers (1)

Muhammad Aamir Ali
Muhammad Aamir Ali

Reputation: 21117

private void requestPublishPermissions(Session session) {
    List<String> PERMISSIONS = Arrays.asList("publish_actions", "publish_stream");
    if (session != null) {
        pendingAnnounce = true;
        Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);

        newPermissionsRequest.setRequestCode(REAUTH_ACTIVITY_CODE);
        Session mSession = Session.openActiveSessionFromCache(this);
        mSession.addCallback(callback);
        mSession.requestNewPublishPermissions(newPermissionsRequest);
    }
}

Upvotes: 1

Related Questions