public class ShareActivityextends AppCompatActivityimplements View.OnClickListener {
private static Uriuri;
// private String path;
private ArrayListpathList =new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share);
findViewById(R.id.bt_share).setOnClickListener(this);
findViewById(R.id.bt_shares).setOnClickListener(this);
findViewById(R.id.bt_share_wechat).setOnClickListener(this);
findViewById(R.id.bt_share_pyq).setOnClickListener(this);
findViewById(R.id.bt_share_qq).setOnClickListener(this);
findViewById(R.id.bt_share_wb).setOnClickListener(this);
findViewById(R.id.bt_share_wechats).setOnClickListener(this);
findViewById(R.id.bt_share_pyqs).setOnClickListener(this);
findViewById(R.id.bt_share_qqs).setOnClickListener(this);
findViewById(R.id.bt_share_wbs).setOnClickListener(this);
}
public void shareText() {
Intent shareIntent =new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT,"<a href=\"http://www.w3school.com.cn\">这是一个链接</a>");
shareIntent.putExtra(Intent.EXTRA_TEXT,"<a href=\"http://www.w3school.com.cn\">This is a link</a>");
shareIntent.setType("text/plain");
//shareIntent.setType("text/html");
//设置分享列表的标题,并且每次都显示分享列表
startActivity(Intent.createChooser(shareIntent,"分享到"));
}
//https://blog.csdn.net/weixin_42165508/article/details/117348499
public static void sharePhotoToWX(Context context, String text, String photoPath) {
/*if (!uninstallSoftware(context, "com.tencent.mm")) {
Toast.makeText(context, "微信没有安装!", Toast.LENGTH_SHORT).show();
return;
}*/
/* File file = new File(photoPath);
if (!file.exists()) {
String tip = "文件不存在";
Toast.makeText(context, tip + " path = " + photoPath, Toast.LENGTH_LONG).show();
return;
}*/
Intent intent =new Intent();
ComponentName componentName =new ComponentName("com.tencent.mm",
"com.tencent.mm.ui.tools.ShareToTimeLineUI");
intent.setComponent(componentName);
intent.setAction("android.intent.action.SEND");
intent.setType("image/*");
intent.putExtra("Kdescription", text);
intent.putExtra(Intent.EXTRA_STREAM,uri);
context.startActivity(intent);
}
// https://www.jianshu.com/p/15eafb9e40f7
// https://www.bbsmax.com/A/gGdXAOg1z4/
// 分享到微信 qq 微博 单图,多图等
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.bt_share:
shareText();
break;
case R.id.bt_shares:
// shareText();
Intent intent =new Intent(Intent.ACTION_PICK,null);
intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,"image/*");
startActivityForResult(intent,2);
break;
case R.id.bt_share_wechat:
ShareFileUtilss.shareImageToWeChat(this,uri);
break;
case R.id.bt_share_pyq:
//sharePhotoToWX(this,"坎坎坷坷扩This is a link",null);
ShareFileUtilss.shareImageToWeChatFriend(this,uri);
break;
case R.id.bt_share_qq:
ShareFileUtilss.shareImageToQQ(this,uri);
break;
case R.id.bt_share_wb:
ShareFileUtilss.shareImageToWeibo(this,uri);
break;
case R.id.bt_share_wechats:
ShareFileUtilss.shareImageToWeChat(this,pathList);
break;
case R.id.bt_share_pyqs:
//sharePhotoToWX(this,"坎坎坷坷扩This is a link",null);
ShareFileUtilss.shareImageToWeChatFriend(this,pathList);
break;
case R.id.bt_share_qqs:
ShareFileUtilss.shareImageToQQ(this,pathList);
break;
case R.id.bt_share_wbs:
ShareFileUtilss.shareImageToWeibo(this,pathList);
break;
}
}
@Override
protected void onActivityResult(int requestCode,int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode ==2){
if(data !=null){
uri = data.getData();
//path=uri.getPath();
pathList.add(uri);
}
}
}
}