Android sharing summary

About the author: CSDN content partner and technical expert, built an APP with tens of millions of daily users from scratch.
Focus on sharing original series of articles in various fields, specializing in java backend, mobile development, business realization, artificial intelligence, etc. I hope everyone will support me.

Insert image description here

1. Introduction

We continue to summarize and learn, review the past and learn the new.

Since someone asked about sharing-related functions a while ago and said they didn’t know where to register, this article will collect them.

This article mainly introduces several domestic mainstream three-party sharing platforms such as QQ, WeChat, Sina Weibo, Alipay, and DingTalk, as well as some aggregate sharing platforms.

2. WeChat sharing

WeChat Development Platform
Android Access Guide

  1. Register > Get application APPID
  2. Access sdk

Add in build.gradle

dependencies {
    
    
    api 'com.tencent.mm.opensdk:wechat-sdk-android:+'
}

In the root build.gradle file of the project, add the following code

buildscript {
    
    
    repositories {
    
    
        jcenter()       // 原有 jCenter 引用可继续保留
        mavenCentral()
    }
}

allprojects {
    
    
    repositories {
    
    
        jcenter()      // 原有 jCenter 引用可继续保留
        mavenCentral()
    }
}

ConfigureAndroidManifest


  1. Receive WeChat requests and return values

Create a new wxapi directory in the directory corresponding to your package name, and add a WXEntryActivity class in the wxapi directory, which inherits from Activity


public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
    
    

    private IWXAPI api;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
    
    
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this, CorePackageConfig.APPINFO.WEIXIN_APPID, false);
        try {
    
    
            Intent intent = getIntent();
            api.handleIntent(intent, this);
        } catch (Exception e) {
    
    
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
    
    
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {
    
    
        // 微信发送请求到第三方应用时,会回调到该方法
    }

    @Override
    public void onResp(BaseResp baseResp) {
    
    

    }


}

me

<activity
    android:name=".wxapi.WXEntryActivity"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    android:exported="true"
    android:taskAffinity="填写你的包名"
    android:launchMode="singleTask">
</activity>

Add obfuscation

  1. debug



    private final IWXAPI iwxapi;

    /**
     * 分享文本
     */
    @Override
    public void shareText(Activity activity, Entity Entity, ShareListener listener) {
    
    
        String shareText = Entity.getDesc();
        if (TextUtil.isEmpty(shareText)) {
    
    
            return;
        }

        WXTextObject textObj = new WXTextObject();
        textObj.text = shareText;

        WXMediaMessage msg = new WXMediaMessage();
        msg.mediaObject = textObj;
        msg.description = shareText;
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = buildTransaction("text");
        req.message = msg;
        req.scene = getSendScene(Entity.getShare_type());
        iwxapi.sendReq(req);
        addOnStarListener(listener);
    }

3. QQ, QQ Zone (Qzone) sharing

QQ Internet official website
Documentation materials

  1. Register > Get application APPID
  2. download sdk
  3. Connect to sdk
    Copy the downloaded open_sdk_xxx_lite.jar to the lib directory

Add in build.gradle

dependencies {
    
    
    implementation fileTree(dir: 'libs', include: '*.jar')
}

ConfigureAndroidManifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


<application>


 <activity
       android:name="com.tencent.tauth.AuthActivity"
       android:noHistory="true"
       android:launchMode="singleTask" >
    <intent-filter>
           <action android:name="android.intent.action.VIEW" />
           <category android:name="android.intent.category.DEFAULT" />
           <category android:name="android.intent.category.BROWSABLE" />
           <data android:scheme="tencent你的AppId" />
    </intent-filter>
 </activity>
<activity
       android:name="com.tencent.connect.common.AssistActivity"
       android:configChanges="orientation|keyboardHidden"
       android:screenOrientation="behind" 
       android:theme="@android:style/Theme.Translucent.NoTitleBar" />
       
       
       
       
       
<application>
  1. debug
public class QQShareMediaAction {
    
    

    private final Tencent mTencent;

    public QQShareMediaAction(Activity activity) {
    
    
        mTencent = Tencent.createInstance(qqAppId(), activity.getApplicationContext(), "");
    }

    /**
     * 分享文本
     * QQ不支持分享纯文本
     */

    public void shareText(Activity activity, ShareEntity ShareEntity, ShareManager.CustomShareListener listener) {
    
    
        shareWeb(activity, ShareEntity, listener);
    }

    /**
     * 分享图片
     * 只支持本地图片
     */
    public void shareImage(Activity activity, ShareEntity ShareEntity, ShareManager.CustomShareListener listener) {
    
    
        String shareImgUrl = ShareEntity.getImg_url();
        if (ShareTextUtil.isEmpty(shareImgUrl) || !limitSize(ShareEntity.getImg_url(), listener)) {
    
    
            return;
        }
        
        Bundle params = new Bundle();
        params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_IMAGE);
        params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, shareImgUrl);
        mTencent.shareToQQ(activity, params, listener);
        addOnStarListener(listener);
    }

}

4. Sina Weibo

Login Sina Weibo Open Platform

Mobile client access instructions

Android SDK documentation

The authorization callback page and deauthorization callback page are set in Application Information -> Advanced Information. For the specific location of the iOS application, please refer to the figure below. Note that the authorization callback page here needs to be consistent with the redirectURL parameter in the code. Note that the bundle ID setting must be consistent with the project.

5. DingTalk

Login DingTalk Open Platform

DingTalk sharing introduction

6. Alipay

Alipay open platform

Log in with your Alipay account, register the APP, click Apply > Add the sharing function in the function information > Finally apply for online review and pass

7. Enterprise WeChat

Enterprise WeChat official platform

To use the Enterprise WeChat sharing function module, you need to first register a corporate account on the Enterprise WeChat official platform, create an iOS or Android application, and enable the "Enterprise WeChat Authorized Login" interface.

8. Aggregation and sharing platform

Such as umeng, aurora and other domestic aggregation sharing.

9. Recommended reading

Java column

SQL Column

Data Structures and Algorithms

Android learning column

ddd

Guess you like

Origin blog.csdn.net/fumeidonga/article/details/134903855