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, "分享"));
}
});
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, "分享"));
}
});
相关文章推荐
- 社交巨头三国杀:微信、WhatsApp、Line到底有啥区别?
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件