ShareSDK的使用


 

ShareSDK的使用

Share SDK 的使用

步驟:

1、注冊開發者賬號

官網注冊賬號:http://www.mob.com/#/

2、創建應用

1、創建項目

2、在官網創建項目

3、下載SDK

1、在官網選擇要分享的平台並下載SDK

2、點擊資源中的QuickIntegrater.jar填寫應用名和包名,生產資源文件,將生產的項目名文件下對應的資源文件拷貝到工程對應的目錄下

3、添加對應權限

<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>

4、添加Activity信息

 <activity
    android:name="com.mob.tools.MobUIShell"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="stateHidden|adjustResize" >
    <intent-filter>
        <data android:scheme="tencent100371282" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
 </activity>

5、如果您集成了微信或者易信,還需要添加下面兩個Activity

<!--微信分享回調 -->
 <activity
     android:name=".wxapi.WXEntryActivity"
     android:theme="@android:style/Theme.Translucent.NoTitleBar"
     android:configChanges="keyboardHidden|orientation|screenSize"
     android:exported="true"
     android:screenOrientation="portrait" /> 

<!--易信分享回調 -->
 <activity
     android:name=".yxapi.YXEntryActivity"
     android:theme="@android:style/Theme.Translucent.NoTitleBar"
     android:configChanges="keyboardHidden|orientation|screenSize"
     android:exported="true"
     android:screenOrientation="portrait" />

6、替換mob后台申請的Appkey與各個平台申請的key

<?xml version="1.0" encoding="utf-8"?>
<DevInfor>
<!--
    說明:

    1、表格中的第一項
        <ShareSDK 
            AppKey="112ecf7087b1e" />
    是必須的,其中的AppKey是您在ShareSDK上注冊的開發者帳號的AppKey

    2、所有集成到您項目的平台都應該為其在表格中填寫相對應的開發者信息,以新浪微博為例:
        <SinaWeibo
            Id="1"
            SortId="1"
            AppKey="568898243"
            AppSecret="38a4f8204cc784f81f9f0daaf31e02e3"
            RedirectUrl="http://www.mob.com"
            Enable="true" />
    其中的SortId是此平台在分享列表中的位置,由開發者自行定義,可以是任何整型數字,數值越大
    越靠后AppKey、AppSecret和RedirectUrl是您在新浪微博上注冊開發者信息和應用后得到的信息
    Id是一個保留的識別符,整型,ShareSDK不使用此字段,供您在自己的項目中當作平台的識別符。
    Enable字段表示此平台是否有效,布爾值,默認為true,如果Enable為false,即便平台的jar包
    已經添加到應用中,平台實例依然不可獲取。

    各個平台注冊應用信息的地址如下:
        新浪微博        http://open.weibo.com
        騰訊微博        http://dev.t.qq.com
        QQ空間          http://connect.qq.com/intro/login/
        微信好友        http://open.weixin.qq.com
        Facebook       https://developers.facebook.com
        Twitter        https://dev.twitter.com
        人人網          http://dev.renren.com
        開心網          http://open.kaixin001.com
        搜狐微博        http://open.t.sohu.com
        網易微博        http://open.t.163.com
        豆瓣           http://developers.douban.com

        有道雲筆記      http://note.youdao.com/open/developguide.html#app
        印象筆記        https://dev.evernote.com/
        Linkedin       https://developer.linkedin.com
        FourSquare     https://developer.foursquare.com/
        搜狐隨身看      https://open.sohu.com/
        Flickr         http://www.flickr.com/services/
        Pinterest      http://developers.pinterest.com/
        Tumblr         http://www.tumblr.com/developers
        Dropbox        https://www.dropbox.com/developers
        Instagram      http://instagram.com/developer#
        VKontakte      http://vk.com/dev
        易信好友        http://open.yixin.im/
        明道             http://open.mingdao.com/
        Line           http://media.line.me/zh-hant/
        Pocket         http://getpocket.com/developer/apps/new
-->

<ShareSDK 
    AppKey = "112ecf7087b1e"/> <!-- 修改成你在sharesdk后台注冊的應用的appkey"-->

<!-- ShareByAppClient標識是否使用微博客戶端分享,默認是false -->
<SinaWeibo
    Id="1"
    SortId="1"
    AppKey="568898243"
    AppSecret="38a4f8204cc784f81f9f0daaf31e02e3"
    RedirectUrl="http://www.sharesdk.cn"
    ShareByAppClient="false"
    Enable="true" />

<TencentWeibo
    Id="2" 
    SortId="2"
    AppKey="801307650"
    AppSecret="ae36f4ee3946e1cbb98d6965b0b2ff5c"
    RedirectUri="http://sharesdk.cn"
    Enable="true" />

<!-- ShareByAppClient標識是否使用微博客戶端分享,默認是false -->
<QZone
    Id="3"
    SortId="3"
    AppId="100371282"
    AppKey="aed9b0303e3ed1e27bae87c33761161d"
    ShareByAppClient="false"
    Enable="true" />

<!-- 
    Wechat微信和WechatMoments微信朋友圈的appid是一樣的;

                   注意:開發者不能用我們這兩個平台的appid,否則分享不了

      微信測試的時候,微信測試需要先簽名打包出apk,
    sample測試微信,要先簽名打包,keystore在sample項目中,密碼123456

    BypassApproval是繞過審核的標記,設置為true后AppId將被忽略,故不經過
    審核的應用也可以執行分享,但是僅限於分享文字和圖片,不能分享其他類型,
    默認值為false。此外,微信收藏不支持此字段。
-->
<Wechat
    Id="4"
    SortId="4"
    AppId="wx4868b35061f87885"
    AppSecret="64020361b8ec4c99936c0e3999a9f249"
    BypassApproval="false"
    Enable="true" />

<WechatMoments
    Id="5"
    SortId="5"
    AppId="wx4868b35061f87885"
    AppSecret="64020361b8ec4c99936c0e3999a9f249"
    BypassApproval="false"
    Enable="true" />

<WechatFavorite
    Id="6"
    SortId="6"
    AppId="wx4868b35061f87885"
    AppSecret="64020361b8ec4c99936c0e3999a9f249"
    Enable="true" />

<!-- ShareByAppClient標識是否使用微博客戶端分享,默認是false -->
<QQ
    Id="7"
    SortId="7"
    AppId="100371282"
    AppKey="aed9b0303e3ed1e27bae87c33761161d"
    ShareByAppClient="true"
    Enable="true" />

<Facebook
    Id="8"
    SortId="8"
    ConsumerKey="107704292745179"
    ConsumerSecret="38053202e1a5fe26c80c753071f0b573"
    RedirectUrl="http://mob.com"
    Enable="true" />

<Twitter
    Id="9"
    SortId="9"
    ConsumerKey="LRBM0H75rWrU9gNHvlEAA2aOy"
    ConsumerSecret="gbeWsZvA9ELJSdoBzJ5oLKX0TU09UOwrzdGfo9Tg7DjyGuMe8G"
    CallbackUrl="http://mob.com"
    Enable="true" />

<Renren
    Id="10"
    SortId="10"
    AppId="226427"
    ApiKey="fc5b8aed373c4c27a05b712acba0f8c3"
    SecretKey="f29df781abdd4f49beca5a2194676ca4"
    Enable="true" />

<KaiXin
    Id="11"
    SortId="11"
    AppKey="358443394194887cee81ff5890870c7c"
    AppSecret="da32179d859c016169f66d90b6db2a23"
    RedirectUri="http://www.sharesdk.cn"
    Enable="true" />

<Email
    Id="12" 
    SortId="12"
    Enable="true" />

<ShortMessage
    Id="13" 
    SortId="13"
    Enable="true" />

<Douban
    Id="16"
    SortId="16"
    ApiKey="031a96a3aa8b28af094fc3eaffa17a0d"
    Secret="2e675e730571b75d"
    RedirectUri="http://mob.com"
    Enable="true" />

<YouDao
    Id="17"
    SortId="17"
    HostType="product"
    ConsumerKey="dcde25dca105bcc36884ed4534dab940"
    ConsumerSecret="d98217b4020e7f1874263795f44838fe"
    RedirectUri="http://www.sharesdk.cn/"
    Enable="true" />

<SohuSuishenkan
    Id="18"
    SortId="18"
    AppKey="e16680a815134504b746c86e08a19db0"
    AppSecret="b8eec53707c3976efc91614dd16ef81c"
    RedirectUri="http://sharesdk.cn"
    Enable="true" />

<!-- 
    在中國大陸,印象筆記有兩個服務器,一個是沙箱(sandbox),一個是生產服務器(china)。
    一般你注冊應用,它會先讓你使用sandbox,當你完成測試以后,可以到
    http://dev.yinxiang.com/support/上激活你的ConsumerKey,激活成功后,修改HostType
    為china就好了。至於如果您申請的是國際版的印象筆記(Evernote),則其生產服務器類型為
    “product”。

    如果目標設備上已經安裝了印象筆記客戶端,ShareSDK允許應用調用本地API來完成分享,但
    是需要將應用信息中的“ShareByAppClient”設置為true,此字段默認值為false。
-->
<Evernote
    Id="19"
    SortId="19"
    HostType="sandbox"
    ConsumerKey="sharesdk-7807"
    ConsumerSecret="d05bf86993836004"
    ShareByAppClient="false"
    Enable="true" />

    <LinkedIn
        Id="20"
        SortId="20"
        ApiKey="ejo5ibkye3vo"
        SecretKey="cC7B2jpxITqPLZ5M" 
        RedirectUrl="http://sharesdk.cn"
        Enable="true" />

     <GooglePlus
        Id="21"
        SortId="21"
        Enable="true" />

     <FourSquare
        Id="22"
        SortId="22"
        ClientID="G0ZI20FM30SJAJTX2RIBGD05QV1NE2KVIM2SPXML2XUJNXEU"
        ClientSecret="3XHQNSMMHIFBYOLWEPONNV4DOTCDBQH0AEMVGCBG0MZ32XNU"
        RedirectUrl="http://www.sharesdk.cn"
        Enable="true" />

    <Pinterest
        Id="23"
        SortId="23"
        ClientId="1432928"
        Enable="true" />

     <Flickr
        Id="24"
        SortId="24"
        ApiKey="33d833ee6b6fca49943363282dd313dd"
        ApiSecret="3a2c5b42a8fbb8bb"
        RedirectUri="http://www.sharesdk.cn"
        Enable="true" />

    <Tumblr
        Id="25"
        SortId="25"
        OAuthConsumerKey="2QUXqO9fcgGdtGG1FcvML6ZunIQzAEL8xY6hIaxdJnDti2DYwM"
        SecretKey="3Rt0sPFj7u2g39mEVB3IBpOzKnM3JnTtxX2bao2JKk4VV1gtNo"
        CallbackUrl="http://sharesdk.cn"
        Enable="true" />

    <Dropbox
        Id="26"
        SortId="26"
        AppKey="i5vw2mex1zcgjcj" 
        AppSecret="3i9xifsgb4omr0s"
        RedirectUri="https://www.sharesdk.cn"
        Enable="true" />

    <VKontakte 
        Id="27"
        SortId="27"
        ApplicationId="3921561"
        Enable="true" />

    <Instagram 
        Id="28"
        SortId="28"
        ClientId="ff68e3216b4f4f989121aa1c2962d058"
        ClientSecret="1b2e82f110264869b3505c3fe34e31a1"
        RedirectUri="http://sharesdk.cn"
        Enable="true" />

    <!-- 
        Yixin易信和YixinMoments易信朋友圈的appid是一樣的;

                       注意:開發者不能用我們這兩個平台的appid,否則分享不了

         易信測試的時候需要先簽名打包出apk,
        sample測試易信,要先簽名打包,keystore在sample項目中,密碼123456

        BypassApproval是繞過審核的標記,設置為true后AppId將被忽略,故不經過
        審核的應用也可以執行分享,但是僅限於分享文字或圖片,不能分享其他類型,
        默認值為false。
    -->
    <Yixin 
        Id="29"
        SortId="29"
        AppId="yx0d9a9f9088ea44d78680f3274da1765f"
        BypassApproval="true"
        Enable="true" />

    <YixinMoments
        Id="30"
        SortId="30"
        AppId="yx0d9a9f9088ea44d78680f3274da1765f"
        BypassApproval="true"
        Enable="true" />

    <Mingdao
        Id="31"
        SortId="31"
        AppKey="EEEE9578D1D431D3215D8C21BF5357E3"
        AppSecret="5EDE59F37B3EFA8F65EEFB9976A4E933"
        RedirectUri="http://sharesdk.cn"
        Enable="true" />

    <Line
        Id="32"
        SortId="32"
        Enable="true" />

    <KakaoTalk
        Id="33"
        SortId="33"
        AppKey="48d3f524e4a636b08d81b3ceb50f1003"
        Enable="true" />

    <KakaoStory
        Id="34"
        SortId="34"
        AppKey="48d3f524e4a636b08d81b3ceb50f1003"
        Enable="true" />

    <WhatsApp
        Id="35"
        SortId="35"
        Enable="true" />

    <Bluetooth
        Id="36"
        SortId="36"
        Enable="false" />

    <Pocket
        Id="37"
        SortId="37"
        ConsumerKey="32741-389c565043c49947ba7edf05"
        Enable="true" />

    <Instapaper
        Id="38"
        SortId="38"
        ConsumerKey="4rDJORmcOcSAZL1YpqGHRI605xUvrLbOhkJ07yO0wWrYrc61FA"
        ConsumerSecret="GNr1GespOQbrm8nvd7rlUsyRQsIo3boIbMguAl9gfpdL0aKZWe"
        Enable="true" />

    <FacebookMessenger
        Id="39"
        SortId="39"
        ConsumerKey="107704292745179"
        ConsumerSecret="38053202e1a5fe26c80c753071f0b573"
        RedirectUrl="http://mob.com"
        Enable="true" />

     <Alipay
        Id="52"
        SortId="52"  
        AppId="2015072400185895"
        Enable="true"/>
</DevInfor>

7、添加分享代碼

private void showShare(){
    ShareSDK.initSDK(context);
    OnekeyShare oks = new OnekeyShare(); 
    // 分享時Notification的圖標和文字
    oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
    oks.setText("我是分享文本");
    oks.setImageUrl("http://f1.sharesdk.cn/imgs/2014/05/21/oESpJ78_533x800.jpg"); 
    // 啟動分享GUI
    oks.show(context);
}

運行代碼, 可以看見應用已經可以分享至各個平台。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM