zoukankan      html  css  js  c++  java
  • Android 微信、qq分享文本 (Intent)

    文章:

    https://www.jianshu.com/p/9522e24713e1

    1、定义一个工具类(PlatformUtil)

    调用方式如:Platformutil.isInstallApp(context,PlatformUtil.PACKAGE_WECHAT);// 判断微信是否安装

    public class PlatformUtil {
        public static final String PACKAGE_WECHAT = "com.tencent.mm";
        public static final String PACKAGE_MOBILE_QQ = "com.tencent.mobileqq";
        public static final String PACKAGE_QZONE = "com.qzone";
        public static final String PACKAGE_SINA = "com.sina.weibo";
    
        // 判断是否安装指定app
        public static boolean isInstallApp(Context context, String app_package){
            final PackageManager packageManager = context.getPackageManager();
            List<PackageInfo> pInfo = packageManager.getInstalledPackages(0);
            if (pInfo != null) {
                for (int i = 0; i < pInfo.size(); i++) {
                    String pn = pInfo.get(i).packageName;
                    if (app_package.equals(pn))) {
                        return true;
                    }
                }
            }
            return false;
        }
    }

    2、qq分享

    /**
    * 直接分享纯文本内容至QQ好友
    * @param mContext
    * @param content
    */
    public static void shareQQ(Context mContext, String content) {
    if (PlatformUtil.isInstallApp(mContext, PlatformUtil.PACKAGE_MOBILE_QQ)) {
    Intent intent = new Intent("android.intent.action.SEND");
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
    intent.putExtra(Intent.EXTRA_TEXT, content);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(new ComponentName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity"));
    mContext.startActivity(intent);
    } else {
    Toast.makeText(mContext, "您需要安装QQ客户端", Toast.LENGTH_LONG).show();
    }
    }
    调用:
    shareQQ(当前上下文,要传的文本)

    shareQQ(getContext(),newsList.get(position).getTitle().concat(newsList.get(position).getUrl()));

    3、微信分享

     /**
    * 直接分享文本到微信好友
    *
    * @param context 上下文
    */
    public void shareWechatFriend(Context context, String content) {
    if (PlatformUtil.isInstallApp(context, PlatformUtil.PACKAGE_WECHAT)) {
    Intent intent = new Intent();
    ComponentName cop = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI");
    intent.setComponent(cop);
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra("android.intent.extra.TEXT", content);
    // intent.putExtra("sms_body", content);
    intent.putExtra("Kdescription", !TextUtils.isEmpty(content) ? content : "");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
    } else {
    Toast.makeText(context, "您需要安装微信客户端", Toast.LENGTH_LONG).show();
    }
    }

    调用:
    shareWechatFriend(getContext(),newsList.get(position).getTitle().concat(newsList.get(position).getUrl()));
  • 相关阅读:
    工具
    BZOJ 1202: [HNOI2005]狡猾的商人
    BZOJ 4562: [Haoi2016]食物链
    BZOJ 1922: [Sdoi2010]大陆争霸
    BZOJ 2429: [HAOI2006]聪明的猴子
    BZOJ 1083: [SCOI2005]繁忙的都市
    BZOJ 1012: [JSOI2008]最大数maxnumber
    Luogu P1078 文化之旅
    快速读入
    [HNOI2014]道路堵塞
  • 原文地址:https://www.cnblogs.com/guochangxin/p/11466122.html
Copyright © 2011-2022 走看看