激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Android - Android將內(nèi)容分享到QQ和微信實(shí)例代碼

Android將內(nèi)容分享到QQ和微信實(shí)例代碼

2022-03-03 14:59Android教程網(wǎng) Android

這篇文章主要介紹了Android將內(nèi)容分享到QQ和微信實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

具體代碼如下所示:

?
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package dmpte.sharewechat;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.MediaStore;
import android.widget.Toast;
import java.util.List;
/**
 * Created by Administrator on 2018/6/25.
 */
public class AndroidShare {
  /**
   * 上下文
   */
  private Context context;
  /**
   * 文本類型
   *
   */
  public static int TEXT = 0;
  /**
   * 圖片類型
   */
  public static int DRAWABLE = 1;
  public AndroidShare(Context context) {
    this.context = context;
  }
  /**
   * 分享到QQ好友
   *
   * @param msgTitle
   *      (分享標(biāo)題)
   * @param msgText
   *      (分享內(nèi)容)
   * @param type
   *      (分享類型)
   * @param drawable
   *      (分享圖片,若分享類型為AndroidShare.TEXT,則可以為null)
   */
  public void shareQQFriend(String msgTitle, String msgText, int type,
               Bitmap drawable) {
    shareMsg("com.tencent.mobileqq",
        "com.tencent.mobileqq.activity.JumpActivity", "QQ", msgTitle,
        msgText, type, drawable);
  }
  /**
   * 分享到微信好友
   *
   * @param msgTitle
   *      (分享標(biāo)題)
   * @param msgText
   *      (分享內(nèi)容)
   * @param type
   *      (分享類型)
   * @param drawable
   *      (分享圖片,若分享類型為AndroidShare.TEXT,則可以為null)
   */
  public void shareWeChatFriend(String msgTitle, String msgText, int type,
                 Bitmap drawable) {
    shareMsg("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI", "微信",
        msgTitle, msgText, type, drawable);
  }
  /**
   * 分享到微信朋友圈(分享朋友圈一定需要圖片)
   *
   * @param msgTitle
   *      (分享標(biāo)題)
   * @param msgText
   *      (分享內(nèi)容)
   * @param drawable
   *      (分享圖片)
   */
  public void shareWeChatFriendCircle(String msgTitle, String msgText,
                    Bitmap drawable) {
    shareMsg("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI",
        "微信", msgTitle, msgText, AndroidShare.DRAWABLE, drawable);
  }
  /**
   * 點(diǎn)擊分享的代碼
   *
   * @param packageName
   *      (包名,跳轉(zhuǎn)的應(yīng)用的包名)
   * @param activityName
   *      (類名,跳轉(zhuǎn)的頁面名稱)
   * @param appname
   *      (應(yīng)用名,跳轉(zhuǎn)到的應(yīng)用名稱)
   * @param msgTitle
   *      (標(biāo)題)
   * @param msgText
   *      (內(nèi)容)
   * @param type
   *      (發(fā)送類型:text or pic 微信朋友圈只支持pic)
   */
  @SuppressLint("NewApi")
  private void shareMsg(String packageName, String activityName,
             String appname, String msgTitle, String msgText, int type,
             Bitmap drawable) {
    if (!packageName.isEmpty() && !isAvilible(context, packageName)) {// 判斷APP是否存在
      Toast.makeText(context, "請(qǐng)先安裝" + appname, Toast.LENGTH_SHORT)
          .show();
      return;
    }
    Intent intent = new Intent("android.intent.action.SEND");
    if (type == AndroidShare.TEXT) {
      intent.setType("text/plain");
    } else if (type == AndroidShare.DRAWABLE) {
      intent.setType("image/*");
//     BitmapDrawable bd = (BitmapDrawable) drawable;
//     Bitmap bt = bd.getBitmap();
      final Uri uri = Uri.parse(MediaStore.Images.Media.insertImage(
          context.getContentResolver(), drawable, null, null));
      intent.putExtra(Intent.EXTRA_STREAM, uri);
    }
    intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);
    intent.putExtra(Intent.EXTRA_TEXT, msgText);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (!packageName.isEmpty()) {
      intent.setComponent(new ComponentName(packageName, activityName));
      context.startActivity(intent);
    } else {
      context.startActivity(Intent.createChooser(intent, msgTitle));
    }
  }
  /**
   * 判斷相對(duì)應(yīng)的APP是否存在
   *
   * @param context
   * @param packageName
   * @return
   */
  public boolean isAvilible(Context context, String packageName) {
    PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
    for (int i = 0; i < pinfo.size(); i++) {
      if (((PackageInfo) pinfo.get(i)).packageName
          .equalsIgnoreCase(packageName))
        return true;
    }
    return false;
  }
  /**
   * 指定分享到qq
   * @param context
   * @param bitmap
   */
  public void sharedQQ(Activity context, Bitmap bitmap){
    Uri uri = Uri.parse(MediaStore.Images.Media.insertImage(
        context.getContentResolver(), BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher), null, null));
    Intent imageIntent = new Intent(Intent.ACTION_SEND);
    imageIntent.setPackage("com.tencent.mobileqq");
    imageIntent.setType("image/*");
    imageIntent.putExtra(Intent.EXTRA_STREAM, uri);
    imageIntent.putExtra(Intent.EXTRA_TEXT,"您的好友邀請(qǐng)您進(jìn)入天好圈");
    imageIntent.putExtra(Intent.EXTRA_TITLE,"天好圈");
    context.startActivity(imageIntent);
  }
}

然后是使用

?
1
2
3
4
5
6
7
8
9
public void shareQQ(View view) {
    AndroidShare androidShare = new AndroidShare(this);
    androidShare.shareQQFriend("這是標(biāo)題", "這是內(nèi)容", AndroidShare.TEXT, null);
  }
 
  public void shareWechat(View view) {
    AndroidShare androidShare = new AndroidShare(this);
    androidShare.shareWeChatFriend("這是標(biāo)題", "這是內(nèi)容", AndroidShare.TEXT, null);
  }

就是這么簡單

總結(jié)

以上所述是小編給大家介紹的Android將內(nèi)容分享到QQ和微信實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日本特级a一片免费观看 | 欧美性生活视频免费 | 一级毛片特黄 | 久久久久久久久久久久免费 | 欧美人与性禽动交精品 | 日日天日日夜日日摸 | 成人av一区二区免费播放 | 国产精品久久久久国产精品三级 | 久久免费视频3 | 中文字幕电影免费播放 | 蜜桃视频在线免费播放 | 免费专区 - 91爱爱 | 全黄性色大片 | 私库av在线免费观看 | 性感美女一级毛片 | 看片一区 | 欧美性生活久久 | 91中文在线 | 日本欧美一区二区三区在线播 | 草草影院地址 | 性欧美videos 另类喷潮 | xnxx 日本免费| 精品一区二区久久久 | 精品中文字幕久久久久四十五十骆 | 精品一区免费 | 羞羞的视频免费在线观看 | 日韩精品久久久久久久九岛 | 国产欧美一区二区三区免费看 | 一级毛片免费大片 | 欧美人成在线视频 | 美女黄视频在线观看 | 国产成人av一区 | 国产黄色录像片 | 久久免费视频一区二区三区 | 久久久久久中文字幕 | 久久99综合久久爱伊人 | 伦一区二区三区中文字幕v亚洲 | 爱射av| 蜜桃av网 | 99精品国产视频 | 二级大黄大片高清在线视频 |