欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android第三方分享

程序员文章站 2022-07-03 14:54:55
第一步:在module的build.gradle添加apply from: '../MobSDK.gradle'第二步:在根目录的build.gradle添加classpath 'com.mob.sdk:MobSDK:+'第三步:在根目录创建MobSDK.gradle文件MobSDK.gradle文件信息,直接复制即可,里面包含了所有的分享路径,根据自己需要取舍apply plugin: 'com.mob.sdk'MobSDK { appKey "moba0b0c...

第一步:在module的build.gradle添加apply from: '../MobSDK.gradle'

Android第三方分享

第二步:在根目录的build.gradle添加classpath 'com.mob.sdk:MobSDK:+'

Android第三方分享

第三步:在根目录创建MobSDK.gradle文件

Android第三方分享

MobSDK.gradle文件信息,直接复制即可,里面包含了所有的分享路径,根据自己需要取舍

apply plugin: 'com.mob.sdk'

MobSDK {

    appKey "moba0b0c0d0"
    appSecret "5713f0d88511f9f4cf100cade0610a34"

    /* MobLink {
         uriScheme "moba0b0c0d0://cn.sharesdk.demo"
         appLinkHost "ahmn.t4m.cn"
     }*/

    //https true

    ShareSDK {

        loopShare true

        //平台配置信息
        devInfo {

            SinaWeibo {
                id 1
                sortId 59
                appKey "568898243"
                appSecret "38a4f8204cc784f81f9f0daaf31e02e3"
                callbackUri "http://www.sharesdk.cn"
                shareByAppClient true
                enable true
            }

            TencentWeibo {
                id 2
                sortId 2
                appKey "801307650"
                appSecret "ae36f4ee3946e1cbb98d6965b0b2ff5c"
                callbackUri "http://sharesdk.cn"
                enable true
            }

            QZone {
                id 3
                sortId 3
                appId "100371282"
                appKey "aed9b0303e3ed1e27bae87c33761161d"
                shareByAppClient true
                bypassApproval false
                enable true
            }

            //分享QQ小程序专用
            /*QZone {
                id 3
                sortId 3
                appId "222222"
                appKey "aed9b0303e3ed1e27bae87c33761161d"
                shareByAppClient true
                bypassApproval false
                enable true
            }*/

            /* Wechat微信和WechatMoments微信朋友圈的appid是一样的;
           注意:开发者不能用我们这两个平台的appid,否则分享不了
           微信测试的时候,微信测试需要先签名打包出apk,
           sample测试微信,要先签名打包,keystore在sample项目中,密码123456
           BypassApproval是绕过审核的标记,设置为true后AppId将被忽略,故不经过
           审核的应用也可以执行分享,但是仅限于分享文字和图片,不能分享其他类型,
           默认值为false。此外,微信收藏不支持此字段。wx4868b35061f87885

           <!--要分享微信小应用程序时用userName,path-->*/

            Wechat {
                id 4
                sortId 4
                appId "wx4868b35061f87885"
                appSecret "64020361b8ec4c99936c0e3999a9f249"
                userName "gh_afb25ac019c9"
                path "pages/index/index.html?id=1"
                withShareTicket true
                miniprogramType 0
                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"
                bypassApproval false
                enable true
            }

            QQ {
                id 7
                sortId 7
                appId "100371282"
                appKey "aed9b0303e3ed1e27bae87c33761161d"
                shareByAppClient false
                bypassApproval false
                enable true
            }

            //分享小程序专用
            /*QQ {
                id 7
                sortId 7
                appId "222222"
                appKey "aed9b0303e3ed1e27bae87c33761161d"
                shareByAppClient false
                bypassApproval false
                enable true
            }*/

            Facebook {
                id 8
                sortId 8
                appKey "1412473428822331"
                appSecret "a42f4f3f867dc947b9ed6020c2e93558"
                callbackUri "https://mob.com"
                shareByAppClient true
                enable true
            }

            Twitter {
                id 9
                sortId 9
                appKey "viOnkeLpHBKs6KXV7MPpeGyzE"
                appSecret "NJEglQUy2rqZ9Io9FcAU9p17omFqbORknUpRrCDOK46aAbIiey"
                callbackUri "http://mob.com"
                shareByAppClient true
                enable true

            }

            Renren {
                id 10
                sortId 10
                appId "226427"
                appKey "fc5b8aed373c4c27a05b712acba0f8c3"
                appSecret "f29df781abdd4f49beca5a2194676ca4"
                enable true
            }

            KaiXin {
                id 11
                sortId 11
                appKey "358443394194887cee81ff5890870c7c"
                appSecret "da32179d859c016169f66d90b6db2a23"
                callbackUri "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
                appKey "031a96a3aa8b28af094fc3eaffa17a0d"
                appSecret "2e675e730571b75d"
                callbackUri "http://mob.com"
                enable true
            }

            YouDao {
                id 17
                sortId 17
                hostType "product"
                appKey "dcde25dca105bcc36884ed4534dab940"
                appSecret "d98217b4020e7f1874263795f44838fe"
                callbackUri "http://www.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"
                appKey "sharesdk-7807"
                appSecret "d05bf86993836004"
                shareByAppClient true
                enable true
            }

            LinkedIn {
                id 20
                sortId 20
                appKey "ejo5ibkye3vo"
                appSecret "cC7B2jpxITqPLZ5M"
                callbackUri "http://sharesdk.cn"
                shareByAppClient true
                enable true
            }

            GooglePlus {
                id 21
                sortId 21
                appId "236300675100-am5pm8km7md1memjevq8rl9pg5c4s4b8.apps.googleusercontent.com"
                callbackUri "http://localhost"
                shareByAppClient true
                enable true
            }

            FourSquare {
                id 22
                sortId 22
                appId "G0ZI20FM30SJAJTX2RIBGD05QV1NE2KVIM2SPXML2XUJNXEU"
                appSecret "3XHQNSMMHIFBYOLWEPONNV4DOTCDBQH0AEMVGCBG0MZ32XNU"
                callbackUri "http://www.sharesdk.cn"
                enable true
            }

            Pinterest {
                id 23
                sortId 23
                appId "1432928"
                enable true
            }

            Flickr {
                id 24
                sortId 24
                appKey "33d833ee6b6fca49943363282dd313dd"
                appSecret "3a2c5b42a8fbb8bb"
                callbackUri "http://www.sharesdk.cn"
                enable true
            }

            Tumblr {
                id 25
                sortId 25
                appKey "2QUXqO9fcgGdtGG1FcvML6ZunIQzAEL8xY6hIaxdJnDti2DYwM"
                appSecret "3Rt0sPFj7u2g39mEVB3IBpOzKnM3JnTtxX2bao2JKk4VV1gtNo"
                callbackUri  "http://www.sharesdk.cn"
                enable true
            }

            Dropbox {
                id 26
                sortId 26
                appKey "i5vw2mex1zcgjcj"
                appSecret "3i9xifsgb4omr0s"
                callbackUri "https://www.sharesdk.cn"
                enable true
            }

            VKontakte {
                id 27
                sortId 27
                appId "3921561"
                enable true
            }

            Instagram {
                id 28
                sortId 28
                appId "ff68e3216b4f4f989121aa1c2962d058"
                appSecret "1b2e82f110264869b3505c3fe34e31a1"
                callbackUri "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 false
                enable true
            }

            YixinMoments{
                id 30
                sortId 30
                appId "yx0d9a9f9088ea44d78680f3274da1765f"
                bypassApproval false
                enable true
            }

            Mingdao {
                id 31
                sortId 31
                appKey "EEEE9578D1D431D3215D8C21BF5357E3"
                appSecret "5EDE59F37B3EFA8F65EEFB9976A4E933"
                callbackUri "http://sharesdk.cn"
                enable true
            }

            Line {
                id 32
                sortId 32
                appId "1639219273"
                appSecret "58faad55ffce8bf8f63b59fe6fb702ae"
                callbackUri "https://www.mob.com/"
                callbackscheme "lineauth"
                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
            }

            Pocket {
                id 37
                sortId 37
                appKey "32741-389c565043c49947ba7edf05"
                enable true
            }

            Instapaper {
                id 38
                sortId 38
                appKey "4rDJORmcOcSAZL1YpqGHRI605xUvrLbOhkJ07yO0wWrYrc61FA"
                appSecret "GNr1GespOQbrm8nvd7rlUsyRQsIo3boIbMguAl9gfpdL0aKZWe"
                enable true
            }

            FacebookMessenger {
                id 39
                sortId 39
                appId "107704292745179"
                enable true
            }

            Telegram {
                id 47
                sortId 47
                appKey "782826033"
                callbackUri "http://www.mob.com"
                enable true
            }

            Alipay {
                id 50
                sortId 50
                appId "2015072400185895"
                enable true
            }

            AlipayMoments {
                id 51
                sortId 51
                appId "2015072400185895"
                enable true
            }

            Dingding {
                id 52
                sortId 52
                appId "dingoanxyrpiscaovl4qlw"
                bypassApproval false
                enable true
            }

            Youtube {
                id 53
                sortId 53
                appId "370141748022-bicrnsjfiije93bvdt63dh3728m4shas.apps.googleusercontent.com"
                appSecret "AIzaSyAO06g-0TDpHcsXXO918a7QE3Zdct2bB5E"
                callbackUri "http://localhost"
                shareByAppClient true
                enable true
            }

            Meipai {
                id 54
                sortId 54
                appId "1089867596"
                appSecret "y9ym6rrjjijtkt23qtsc"
                shareByAppClient true
                enable true
            }

            Cmcc {
                id 55
                sortId 55
                appId "300011860247"
                appKey "2D464D8BFCE73A44B4F9DF95A2FDBE1C"
            }

            Reddit {
                id 56
                sortId 56
                appKey "MExDxPuTCtFiRw"
                callbackUri "http://www.sharesdk.cn"
            }

            Telecom {
                id 57
                sortId 57
                appKey "8148612606"
                appSecret "mCltrhUqwshFa86egDTs0491ibaAulKA"
                callbackUri "http://www.sharesdk.cn"
                enable true
            }

            /* app_secret的值为Account Kit 应用密匙 ,不是客户端口令 */
            Accountkit {
                id 58
                sortId 58
                appKey "579465512480462"
                appSecret "8a6383652dd9f23fb0994f03d350d0ca"
                callbackUri "http://www.sharesdk.cn/"
                enable true
            }

            Douyin {
                id 59
                sortId 1
                appKey "aw9ivykfjvi4hpwo"
                appSecret "42b4caa6bda60bd49f05f06d0a4956e1"
                enable true
            }

            Wework {
                id 60
                sortId 60
                appKey "wwa21eaecf93f0e3ba"
                appSecret "dW7e27P7Hc8NiYdRxnbTeOLgfI1ugR72e-PM8uusq2s"
                agentId "1000012"
                schema "wwautha21eaecf93f0e3ba000012"
            }
        }

    }
}

第四步:创建Application,绑定MobSdk

package com.sam.more.base;

import android.app.Application;

import com.mob.MobSDK;

/**
 * Sam on 2020/8/11.
 */

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        MobSDK.init(this);
    }
}

第五步调用分享:

    private void share() {
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();

        // title标题,微信、QQ和QQ空间等平台使用
        oks.setTitle("title");

        // titleUrl QQ和QQ空间跳转链接
        oks.setTitleUrl("http://sharesdk.cn");

        // text是分享文本,所有平台都需要这个字段
        oks.setText("我是分享文本");

        // imagePath是图片的本地路径,Linked-In以外的平台都支持此参数
//        oks.setImagePath("/sdcard/DCIM/Camera/20170102_140855.jpg");//确保SDcard下面存在此张图片
        oks.setImageUrl("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2610404822,661877783&fm=26&gp=0.jpg");

        // url在微信、微博,Facebook等平台中使用
        oks.setUrl("http://sharesdk.cn");

        // comment是我对这条分享的评论,仅在人人网使用
        oks.setComment("我是测试评论文本");

        // 启动分享GUI
        oks.show(this);
    }

 

 

本文地址:https://blog.csdn.net/Jeyden_827/article/details/107949803

相关标签: 第三方 android