admin
2022-08-09 399ac289f80b7a40aa4210341db6b447cacdcf14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.tejia.lijin.app.util.share;
 
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
 
public class ShareTextUtil {
    /**
     * 通过intent分享文字
     *
     * @param context
     * @param text
     * @param packageName
     * @param activityName
     */
    private static void shareTextByIntent(Context context, String text, String packageName, String activityName) {
        Intent intent = new Intent();
        ComponentName comp = new ComponentName(packageName, activityName);
        intent.setComponent(comp);
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
        intent.putExtra(Intent.EXTRA_TEXT, text);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(String.valueOf(Intent.CONTENTS_FILE_DESCRIPTOR), "banli");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);//增加读写权限
        }
        context.startActivity(intent);
    }
 
 
    /**
     * 采用intent的方式分享到微信好友
     *
     * @param text
     */
    public static void shareWXTextByIntent(Context context, String text) {
        shareTextByIntent(context, text, "com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI");
    }
 
 
    /**
     * 分享到微信朋友圈
     *
     * @param context
     * @param text
     */
    public static void shareWXCircleTextByIntent(Context context, String text) {
        shareTextByIntent(context, text, "com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI");
    }
 
 
    /**
     * 分享到QQ
     *
     * @param context
     * @param text
     */
    public static void shareQQTextByIntent(Context context, String text) {
        shareTextByIntent(context, text, "com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");
    }
 
 
    /**
     * 分享到QQ空间
     *
     * @param context
     * @param text
     */
    public static void shareQQZoneTextByIntent(Context context, String text) {
        shareTextByIntent(context, text, "com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");
    }
 
 
    /**
     * 分享到新浪图片
     *
     * @param context
     * @param text
     */
    public static void shareSinaTextByIntent(Context context, String text) {
        shareTextByIntent(context, text, "com.sina.weibo", "com.sina.weibo.sdk.web.WeiboSdkWebActivity");
    }
}