不使用第三方SDK实现微博、微信好友、朋友圈、QQ好友、QQ空间分享
对应app的包名以及Activity:
public static String WeiBoPackageName = "com.sina.weibo";
public static String WeiBoClassName = "com.sina.weibo.composerinde.ComposerDispatchActivity";
public static String WeChatPackageName = "com.tencent.mm";
public static String WeChatCircleClassName = "com.tencent.mm.ui.tools.ShareToTimeLineUI";
public static String WeChatSingleClassName = "com.tencent.mm.ui.tools.ShareImgUI";
public static String QQPackageName = "com.tencent.mobileqq";
public static String QQClassName = "com.tencent.mobileqq.activity.JumpActivity";
public static String QQZonePackageName = "com.qzone";
public static String QQZoneClassName = "com.qzonex.module.operation.ui.QZonePublishMoodActivity";
分享代码
if(Helper.checkInstalled(this, packageName)){
Intent shareIntent = new Intent();
ComponentName comp = new ComponentName(packageName, className);
shareIntent .setComponent(comp);
shareIntent .setAction(Intent.ACTION_SEND);
shareIntent .putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(image_path)));
shareIntent .setType("image/*");
startActivity(Intent.createChooser(shareIntent ,"分享弹窗标题"));
}else{
Helper.showMsg(this,"请先安装XXX!");
}
//checkInstalled()检查APP是否安装
//packageName 包名 className类名
//setType("image/*") 分享类型,其他类型看自己需求
相关代码:
/**
* Update: 2018/2/26 10:43
* Description: 检查是否安装APP
*/
public static boolean checkInstalled(Context context,String packageName){
try{
List<PackageInfo> packages = context.getApplicationContext().getPackageManager().getInstalledPackages(0);
for (PackageInfo info : packages) {
String name = info.packageName.toLowerCase(Locale.ENGLISH);
if (packageName.equals(name)) {
return true;
}
}
}catch (Exception e){
}
return false;
}