com.sina.weibo.sdk.api.share
接口 IWeiboShareAPI


public interface IWeiboShareAPI

该类是进行微博分享的接口类。有以下两种方式进行微博分享:

  • 通过第三方应用唤起微博客户端进行分享;
  • 通过微博客户端唤起第三方应用进行分享。(注:该分享方式需要合作接入,详情请查看:
  • 2、微博原生分享 --> b) 集成分享

    作者:
    SINA

    方法摘要
     boolean checkEnvironment(boolean bShowDownloadDialog)
              检查微博客户端环境是否正常。
     int getWeiboAppSupportAPI()
              获取当前微博客户端程序支持的 SDK 的最高版本号。
     boolean handleWeiboRequest(Intent intent, com.sina.weibo.sdk.api.share.IWeiboHandler.Request handler)
              处理微博客户端发送过来的请求。
     boolean handleWeiboResponse(Intent intent, com.sina.weibo.sdk.api.share.IWeiboHandler.Response handler)
              处理微博客户端分享后的响应数据。
     boolean isWeiboAppInstalled()
              检查用户是否安装了微博客户端程序
     boolean isWeiboAppSupportAPI()
              检查微博是否支持此 SDK。
     boolean launchWeibo()
              启动微博客户端程序。
     boolean registerApp()
              注册第三方应用 到微博客户端中,注册成功后该应用将显示在微博的应用列表中。
     void registerWeiboDownloadListener(com.sina.weibo.sdk.api.share.IWeiboDownloadListener listener)
              注册微博客户端下载的监听器。
     boolean sendRequest(com.sina.weibo.sdk.api.share.BaseRequest request)
              发送微博分享请求给微博客户端程序。
     boolean sendResponse(com.sina.weibo.sdk.api.share.BaseResponse response)
              收到微博客户端程序的请求后,发送对应的应答内容给微博客户端程序。
     

    方法详细信息

    isWeiboAppInstalled

    boolean isWeiboAppInstalled()
    检查用户是否安装了微博客户端程序

    返回:
    如果安装了,返回 true;否则,返回 false。

    isWeiboAppSupportAPI

    boolean isWeiboAppSupportAPI()
    检查微博是否支持此 SDK。

    返回:
    如果支持,返回 true;否则,返回 false。

    getWeiboAppSupportAPI

    int getWeiboAppSupportAPI()
    获取当前微博客户端程序支持的 SDK 的最高版本号。 如果微博版本号 < ApiUtils.BUILD_INT_VER_2_2,不支持 VoiceObject 如果微博版本号 < ApiUtils.BUILD_INT_VER_2_3,不支持 CmdObject

    返回:
    版本号

    registerApp

    boolean registerApp()
    注册第三方应用 到微博客户端中,注册成功后该应用将显示在微博的应用列表中。 默认情况下,如果未安装微博客户端,在注册时,会弹出对话框询问用户是否下载微博客户端。

    返回:
    成功返回 true,会显示在微博第三方列表中,否则不显示

    handleWeiboResponse

    boolean handleWeiboResponse(Intent intent,
                                com.sina.weibo.sdk.api.share.IWeiboHandler.Response handler)
    处理微博客户端分享后的响应数据。

    当从当前应用唤起微博发博器并进行分享后,返回到当前应用时,需要在 Activity#onNewIntentActivity#onCreate 函数中,主动调用该 函数处理分享后的响应数据。在 Activity#onCreate 函数中调用该函数是为了防 止该 Activity 处于后台时,可能会由于内存不足被杀掉了而导致的重新初始化。

    执行流程:本应用->微博->本应用

    参数:
    intent - 数据内容
    handler - 处理应答对应的回调函数
    返回:
    成功返回 true,并调用 IWeiboHandler.Response.onResponse(com.sina.weibo.sdk.api.share.BaseResponse); 失败返回 false,不调用上述回调

    handleWeiboRequest

    boolean handleWeiboRequest(Intent intent,
                               com.sina.weibo.sdk.api.share.IWeiboHandler.Request handler)
    处理微博客户端发送过来的请求。

    当微博客户端唤起当前应用并进行分享时,需要在 Activity#onCreateActivity#onNewIntent 函数中,主动调用该函数来处理客户端发送过来的请求。

    执行流程:微博->本应用->微博

    参数:
    intent - 数据内容
    handler - 处理请求后对应的回调函数
    返回:
    成功返回 true,失败返回 false,并调用 IWeiboHandler.Request.onRequest(com.sina.weibo.sdk.api.share.BaseRequest)

    launchWeibo

    boolean launchWeibo()
    启动微博客户端程序。

    返回:
    启动成功,返回 true;否则,返回 false

    sendRequest

    boolean sendRequest(com.sina.weibo.sdk.api.share.BaseRequest request)
    发送微博分享请求给微博客户端程序。 默认情况下,如果未安装微博客户端,在分享时,会弹出对话框询问用户是否下载微博客户端。

    参数:
    request - 请求的内容。
    返回:
    发送成功,返回 true;否则,返回 false

    sendResponse

    boolean sendResponse(com.sina.weibo.sdk.api.share.BaseResponse response)
    收到微博客户端程序的请求后,发送对应的应答内容给微博客户端程序。

    参数:
    response - 应答数据
    返回:
    响应成功,返回 true;否则,返回 false

    registerWeiboDownloadListener

    void registerWeiboDownloadListener(com.sina.weibo.sdk.api.share.IWeiboDownloadListener listener)
    注册微博客户端下载的监听器。 当用户取消下载时,该监听器的 IWeiboDownloadListener.onCancel() 函数被调用。

    参数:
    listener - 监听微博客户端下载的 Listener

    checkEnvironment

    boolean checkEnvironment(boolean bShowDownloadDialog)
                             throws com.sina.weibo.sdk.exception.WeiboShareException
    检查微博客户端环境是否正常。

    参数:
    bShowDownloadDialog - 如果未安装微博,是否弹出对话框询问用户下载微博客户端
    返回:
    如果微博客户端已安装并且合法,返回 true;否则,返回 false
    抛出:
    com.sina.weibo.sdk.exception.WeiboShareException - 微博客户端不合法时,抛出异常