歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Android ShareSdk 分享錯誤解析

執行sharesdk 快捷分享,分享出錯的提示

列出一些常用的快捷分享

share(message, null, SinaWeibo.NAME);
share(message, null, TencentWeibo.NAME);
share(share_content, null, Wechat.NAME);
share(share_content, null, WechatMoments.NAME);

 

// 新浪微博分享 騰訊微博等只需修改 NAME
  public void share(String text, String photopath, String sharename) {
   Platform.ShareParams sp = new SinaWeibo.ShareParams();
   sp.text = text;
   if (photopath!=null) {
    // sp.imagePath = "/mnt/sdcard/測試分享的圖片.jpg";
    sp.imagePath = photopath;
   }
   Platform weibo = ShareSDK.getPlatform(context, sharename);
   // 設置分享事件回調
   weibo.setPlatformActionListener(new PlatformActionListener() {
    public void onError(Platform platform, int action, Throwable t) {
     // 操作失敗的處理代碼
//     Message m = handler.obtainMessage();
//     m.what = SHARE_FAIL;
//     TestShare.this.handler.sendMessage(m);
     
     Message msg =  handler.obtainMessage();
     msg.what = SHARE_FAIL;
     msg.arg1 = action;
     msg.obj = t;
     WeiBoShareActivity.this.handler.sendMessage(msg);
    }

    public void onComplete(Platform platform, int action,
      HashMap<String, Object> res) {
     // 操作成功的處理代碼
     Message m = handler.obtainMessage();
     m.what = SHARE_SUCCESS;
     WeiBoShareActivity.this.handler.sendMessage(m);

     
    }

    public void onCancel(Platform platform, int action) {
     // 操作取消的處理代碼
     Message m = handler.obtainMessage();
     m.what = SHARE_CANCEL;
     WeiBoShareActivity.this.handler.sendMessage(m);
    }
   });
   // 執行圖文分享
   weibo.share(sp);
  }
 
 
 
 
  private Handler handler = new Handler() {
   /*
    * (non-Javadoc)
    *
    * @see Android.os.Handler#handleMessage(android.os.Message)
    */
   @Override
   public void handleMessage(Message msg) {
    // TODO Auto-generated method stub
    ProgressDlg.cancleDlg();
    switch (msg.what) {
          case SHARE_SUCCESS:
     String successtext = getResources().getString(R.string.share_completed);
     EdjTools.showShortToast(successtext,WeiBoShareActivity.this);
           WeiBoShareActivity.this.finish();
                 
     break;
    case SHARE_FAIL:
     String failtext="";
     
     if (msg.obj instanceof WechatClientNotExistException) {
      failtext = getResources().getString(R.string.wechat_client_inavailable);
     }
     else if (msg.obj instanceof WechatTimelineNotSupportedException) {
      failtext = getResources().getString(R.string.wechat_client_inavailable);
     }
//     java.lang.Throwable: {"ret":5,"seqid":5950018181724704141,"detailerrinfo":
//     {"timestamp":1385346563,"proctime":41,"cmd":1472,"accesstoken":"","clientip":"219.143.8.242","apiname":"weibo.t.add","ret2":5,"appkey":"801400858","ret1":20,"ret4":3515057674,"ret3":75},"msg":"prevent duplicate publication","errcode":75}
     else if (msg.obj instanceof java.lang.Throwable &&  msg.obj.toString()!=null&&msg.obj.toString().contains("prevent duplicate publication")) {
     
      failtext = getResources().getString(R.string.prevent_duplicate);
     }else if(msg.obj.toString().contains("error")){
      failtext = getResources().getString(R.string.share_failed_error);

     }else {
      failtext = getResources().getString(R.string.share_failed);
     }
     EdjTools.showShortToast(failtext,WeiBoShareActivity.this);
     break;
    case SHARE_CANCEL:
     
     break;


    }
   }

  };

 

目前您的微信版本過低或未安裝微信,需要安裝微信才能使用

Google+ 版本過低或者沒有安裝,需要升級或安裝Google+才能使用!

QQ 版本過低或者沒有安裝,需要升級或安裝QQ才能使用!

請稍後發送

 

關於第三個異常、騰訊微博連續發送同樣的內容、並在網頁刪除該微博再次客戶端分享時、出現分享失敗

返回的內容在代碼注釋中

大意是:防止重發的發送  我加入了提示語句  "請稍後發送"

更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11

Copyright © Linux教程網 All Rights Reserved