android – java.lang.UnsupportedOperationException:Session:尝试为具有挂起请求的会话请求新权限

android – java.lang.UnsupportedOperationException:Session:尝试为具有挂起请求的会话请求新权限,第1张

概述下面的代码是用于在 android中使用facebookSDK3.0发布状态更新.如果我使用的是UiLifeCycleHelper类,那么它的运行状况良好.但我想在不使用UiLifeCycleHelper类的情况下在facebook中发布状态.我尝试了下面的代码,它在我的logcat中抛出错误,我的应用程序被强制关闭. public class SampleFBPostActivity exten 下面的代码是用于在 android中使用facebookSDK3.0发布状态更新.如果我使用的是UilifeCycleHelper类,那么它的运行状况良好.但我想在不使用UilifeCycleHelper类的情况下在facebook中发布状态.我尝试了下面的代码,它在我的logcat中抛出错误,我的应用程序被强制关闭.

public class SampleFBPostActivity extends Activity implements OnClickListener {private EditText mPostEditText;private button mDonebutton;private Session mSession;private PendingAction pendingAction = PendingAction.NONE;private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");private enum PendingAction {    NONE,POST_STATUS_UPDATE}@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.fb_post);    mPostEditText = (EditText) findVIEwByID(R.ID.post_text);    mDonebutton = (button) findVIEwByID(R.ID.done_button);    mDonebutton.setonClickListener(this);    mSession = Session.getActiveSession();    if (mSession == null) {        mSession = new Session(this);        Session.setActiveSession(mSession);    }    updateUI();    handlePendingAction();}@OverrIDepublic voID onClick(VIEw v) {    switch (v.getID()) {    case R.ID.done_button:        onClickpoststatusUpdate();        break;    }} private interface GraphObjectWithID extends GraphObject {        String getID();    } private voID showPublishResult(String message,GraphObject result,FacebookRequestError error) {        String Title = null;        String alertMessage = null;        if (error == null) {            Title = getString(R.string.success);            String ID = result.cast(GraphObjectWithID.class).getID();            alertMessage = getString(R.string.successfully_posted_post,message,ID);        } else {            Title = getString(R.string.error);            alertMessage = error.getErrorMessage();        }        new AlertDialog.Builder(this)                .setTitle(Title)                .setMessage(alertMessage)                .setPositivebutton(R.string.ok,null)                .show();    }    private voID onClickpoststatusUpdate() {        performpublish(PendingAction.POST_STATUS_UPDATE);    }    private voID poststatusUpdate(final String message) {        if (mSession != null && hasPublishPermission()) {            Request request = Request                    .newStatusUpdateRequest(Session.getActiveSession(),new Request.Callback() {                        @OverrIDe                        public voID onCompleted(Response response) {                            showPublishResult(message,response.getGraphObject(),response.getError());                        }                    });            request.executeAsync();        } else {            pendingAction = PendingAction.POST_STATUS_UPDATE;        }    }    private boolean hasPublishPermission() {        Session session = Session.getActiveSession();        return session != null && session.getPermissions().contains("publish_actions");    }    private voID performpublish(PendingAction action) {        Session session = Session.getActiveSession();        if (session != null) {            pendingAction = action;            if (hasPublishPermission()) {                handlePendingAction();            } else {                session.requestNewPublishPermissions(new Session.NewPermissionsRequest(this,PERMISSIONS));            }        }    }private voID updateUI() {    Session session = Session.getActiveSession();    boolean enablebuttons = (session != null && session.isOpened());    mDonebutton.setEnabled(enablebuttons);} private voID handlePendingAction() {        PendingAction prevIoUslyPendingAction = pendingAction;        pendingAction = PendingAction.NONE;        switch (prevIoUslyPendingAction) {            case POST_STATUS_UPDATE:                poststatusUpdate(mPostEditText.getText().toString());                break;        }    }}

以下是logcat中的错误:

02-09 14:00:36.126: E/AndroIDRuntime(2396): java.lang.UnsupportedOperationException: Session: an attempt was made to request new permissions for a session that has a pending request.  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at com.facebook.Session.requestNewPermissions(Session.java:968)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at com.facebook.Session.requestNewPublishPermissions(Session.java:501)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at com.facebook.samples.sessionlogin.SampleFBPostActivity.performpublish(SampleFBPostActivity.java:113)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at com.facebook.samples.sessionlogin.SampleFBPostActivity.onClickpoststatusUpdate(SampleFBPostActivity.java:83)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at com.facebook.samples.sessionlogin.SampleFBPostActivity.onClick(SampleFBPostActivity.java:54)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at androID.vIEw.VIEw.performClick(VIEw.java:3511)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at androID.vIEw.VIEw$PerformClick.run(VIEw.java:14105)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at androID.os.Handler.handleCallback(Handler.java:605)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at androID.os.Handler.dispatchMessage(Handler.java:92)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at androID.os.Looper.loop(Looper.java:137)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at androID.app.ActivityThread.main(ActivityThread.java:4424)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at java.lang.reflect.Method.invokeNative(Native Method)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at java.lang.reflect.Method.invoke(Method.java:511)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:551)  02-09 14:00:36.126: E/AndroIDRuntime(2396):   at dalvik.system.NativeStart.main(Native Method)

请不要在解决方案中使用UilifeCycleHelper类来帮助我.提前致谢

解决方法 您是否有特殊原因想要使用UilifecycleHelper?那个课程专门为了让你的生活更轻松,所以你不会遇到这样的问题.

如果必须,最简单的方法是查看UilifecycleHelper中的代码,并将它们复制到Activity中的相应方法.

对于您的特定活动,我看到两个错误:

>您无法随时打开会话(直接调用requestNewPublishPermissions,但您需要先打开会话).调用“新会话”不会打开它.>您没有覆盖onActivityResult方法,这是将信息传递回活动会话所必需的.

总结

以上是内存溢出为你收集整理的android – java.lang.UnsupportedOperationException:Session:尝试为具有挂起请求的会话请求新权限全部内容,希望文章能够帮你解决android – java.lang.UnsupportedOperationException:Session:尝试为具有挂起请求的会话请求新权限所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1129864.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存