您的位置:首页 > 移动开发

Android 分享app到QQ好友、微信好友、朋友圈(无需提供SDK,只需调用相关的Activity)

2016-05-04 15:33 771 查看
//分享到QQ好友

qq = (LinearLayout) view.findViewById(R.id.qq_friend);

qq.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ShareDialogFragment.this.dismiss();
Intent intent = new Intent(Intent.ACTION_SEND); // 地址
ComponentName component = new ComponentName(
"com.tencent.mobileqq",
"com.tencent.mobileqq.activity.JumpActivity");
intent.setComponent(component);
intent.putExtra(Intent.EXTRA_TEXT,
getString(R.string.share_content));
intent.setType("text/plain");
startActivity(Intent.createChooser(intent, "分享"));
}
});

// 分享到微信好友

wechat.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ShareDialogFragment.this.dismiss();
Intent intent = new Intent(Intent.ACTION_SEND); // 地址
ComponentName componentName = new ComponentName(
"com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI");
intent.setComponent(componentName);
intent.putExtra(Intent.EXTRA_TEXT,
getString(R.string.share_content));
intent.setType("text/plain");
startActivity(Intent.createChooser(intent, "分享"));
}
});

// 分享到朋友圈

friendCircle.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ShareDialogFragment.this.dismiss();
Intent intent = new Intent(Intent.ACTION_SEND); // 地址
ComponentName componentName = new ComponentName(
"com.tencent.mm",
"com.tencent.mm.ui.tools.ShareToTimeLineUI");
intent.setComponent(componentName);
System.out.println(new File("android_asset/app_qrcode.png")
.length());
File file=FileUtils
.createFile(AppData.BASE_PATH, "share.png");
try {
FileOutputStream fos = new FileOutputStream(file);
InputStream fis = getActivity().getAssets().open(
"app_qrcode.png");
byte[] buffer = new byte[2048];
int len = 0;
while ((len = fis.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fis.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
Uri u = Uri.fromFile(file);
intent.putExtra(Intent.EXTRA_STREAM, u);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "分享"));
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 微信 qq