Mob’s social sharing integration sharesdk

Next, I'll share a note about my use of sharesdk. In the previous article, we integrated smssdk to complete the function of SMS receiving verification code. Please refer to mob's SMS verification integration smssdk. How to integrate sharesdk into the project when the project has integrated smssdk. In the previous article, we integrated smssdk in the form of importing jar package, Here we introduce sharesdk by creating a module. The main contents are as follows:

Download address of the official website: sharesdk. Select the platform to share when downloading, as shown in the figure below:

The downloaded sharesdk is decompressed as follows. The version downloaded here is sharesdk-android-3.0.0, as shown in the following figure:

First, copy the sharesdk.xml file in the sharesdk to the assets directory in the project. Here, the sharesdk is introduced by introducing modules. The sharesdk mainly introduces the following two LIBS, as shown in the following figure:

The following is a demonstration of the module creation process:

At this point, the module is created. The sharing page provided by the sharesdk is used here, so onekeyshare needs to be introduced.

The process of creating a module is the same as the above. Note that there is an additional SRC, which is the java file to be used, so it must also be referenced, as shown in the following figure:

Copy the SRC folder to main. If there is no error after build, it indicates that the module has been created successfully. The following is just like the corresponding module according to the dependency.

Here, onkeysharelibs depends on mainlibs. Just app depends on onkeysharelibs. Here is a demonstration of how onkeysharelibs depends on mainlibs, as shown in the following figure:

Then, in the same way, app can rely on onkeysharelibs.

Smssdk has been configured here before. You only need to supplement the missing permissions. The following is all the permissions required to integrate smssdk and sharesdk at the same time, as follows:

<!-- 添加必要的权限 -->
<!--SMS SDK-->
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <!--ShareSDK-->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.SYstem_ALERT_WINDOW" />

If smssdk has been configured before, mobuishell has been configured. Just add the missing intentfilter. The integrated smssdk and sharesdk can share mobuishell, as follows:

<activity
    android:name="com.mob.tools.MobUIShell"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    android:configChanges="keyboardHidden|orientation|screenSize"
    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>

    <!-- 调用新浪原生SDK,需要注册的回调activity -->
    <intent-filter>
        <action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>

</activity>

If your project set wechat or wechat circle of friends, please check the package path in the androidmanifest.xml configuration file. You need to create a wxapi directory in the package directory and then place wxentryactivity. If there is no such activity, the callback will check whether there is such activity after wechat sharing. If there is no such activity, an error will be reported:

<activity     
    android:name=".yxapi.YXEntryActivity"     
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    android:configChanges="keyboardHidden|orientation|screenSize" 
    android:exported="true"     
    android:screenOrientation="portrait" />

For details, please refer to the complete integration documentation of Android sharesdk

android:name="com.mob.MobApplication"

<!-- 通过AndroidManifest配置AppKey和AppSecret,如果你选择通过代码配置,则不需要配置以下Meta-data -->
<Meta-data android:name="Mob-AppKey" android:value="你的AppKey"/>
<Meta-data android:name="Mob-AppSecret" android:value="你的AppSecret"/>

// 通过代码注册你的AppKey和AppSecret
MobSDK.init(context,"你的AppKey","你的AppSecret");

Use only one of the above two methods to initialize the sharesdk.

private void showShare() {
     OnekeyShare oks = new OnekeyShare();
     //关闭sso授权
     oks.disableSSOWhenAuthorize(); 
     // title标题,印象笔记、邮箱、信息、微信、人人网和QQ空间使用
     oks.setTitle(getString(R.string.share));
     // titleUrl是标题的网络链接,仅在人人网和QQ空间使用
     oks.setTitleUrl("http://sharesdk.cn");
     // text是分享文本,所有平台都需要这个字段
     oks.setText("我是分享文本");
     // imagePath是图片的本地路径,Linked-In以外的平台都支持此参数
     oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
     // url仅在微信(包括好友和朋友圈)中使用
     oks.setUrl("http://sharesdk.cn");
     // comment是我对这条分享评论,仅在人人网和QQ空间使用
     oks.setComment("我是测试评论文本");
     // site是分享内容的网站名称,仅在QQ空间使用
     oks.setSite(getString(R.string.app_name));
     // siteUrl是分享内容网站地址,仅在QQ空间使用
     oks.setSiteUrl("http://sharesdk.cn");

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

This paper mainly records how to introduce the third-party SDK and page sharing call in the form of module.

You can choose to pay attention to WeChat official account: jzman-blog get the latest updates, and exchange learning together!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>