关闭

根据ShareSDK实现分享功能组件化

标签: ShareSDK
113人阅读 评论(0) 收藏 举报

分享功能组件是以aar文件的形式提供,aar下载地址ShareComponent
本文主要是讲使用步骤

第一步:下载aar文件并导入

这里主要介绍下AndroidStudio中如何导入aar文件。
1、将aar文件放到libs文件下
2、在gradle中配置

repositories {
    flatDir {
        dirs 'libs'
    }
}
dependencies {
    compile(name: 'share_component-debug', ext: 'aar')
}

第二步:在AndroidManifest.xml文件中添加配置

<!--权限申明--!>
<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.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.INTERNET"/>


<!--添加Activity信息(tencent后面的appid要保持和您配置的QQ的appid一致)--!>
<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>

第三步:在代码中配置相关信息

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button mShareBtn;
    private ShareEntity mShareEntity;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mShareBtn = (Button) findViewById(R.id.btn_share);
        mShareBtn.setOnClickListener(this);
        mShareEntity = new ShareEntity();
        mShareEntity.setShareSdkId("116ac5ad7ee88");
        mShareEntity.setShareUrl("http://www.baidu.com");
        mShareEntity.setShareContent("实现分享功能组件化");
        mShareEntity.setShareTitle("分享组件");
        Map<String,ShareKeyEntity> map = new HashMap<>();
        ShareKeyEntity qq = new ShareKeyEntity();
        qq.setKey("1105235873");
        qq.setSecret("cfdcad41a1745760611995c9b9cd672c");
        map.put(ShareComponent.QQ,qq);
        ShareKeyEntity qzone = new ShareKeyEntity();
        qzone.setKey("1105235873");
        qzone.setSecret("cfdcad41a1745760611995c9b9cd672c");
        map.put(ShareComponent.QZONE,qzone);
        ShareKeyEntity sina = new ShareKeyEntity();
        sina.setKey("1968663125");
        sina.setSecret("cfdcad41a1745760611995c9b9cd672c");
        map.put(ShareComponent.SINA,sina);
        ShareKeyEntity wechat = new ShareKeyEntity();
        wechat.setKey("wxa443e9e5eecd5242");
        wechat.setSecret("1d5276b2506ff35a4db1adbc018c9db7");
        map.put(ShareComponent.WECHAT,wechat);
        ShareKeyEntity wechatcomments = new ShareKeyEntity();
        wechatcomments.setKey("wxa443e9e5eecd5242");
        wechatcomments.setSecret("1d5276b2506ff35a4db1adbc018c9db7");
        map.put(ShareComponent.WECHAT_MOMENTS,wechatcomments);
        mShareEntity.setShareKeyMap(map);

    }

    @Override
    public void onClick(View view) {

        int id = view.getId();
        switch (id) {
            case R.id.btn_share:
                ShareComponent.getInstance().share(MainActivity.this,mShareBtn,mShareEntity);
                break;
            default:
                break;
        }

    }
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2672次
    • 积分:142
    • 等级:
    • 排名:千里之外
    • 原创:12篇
    • 转载:0篇
    • 译文:0篇
    • 评论:1条
    最新评论