Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

4.8. 分享

4.8.1. 分享文本内容

			
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain"); //分享的是文本类型
shareIntent.putExtra(Intent.EXTRA_TEXT, "文本内容");//分享出去的内容
startActivity(shareIntent);    //注意这里的变化

//startActivity(Intent.createChooser(shareIntent, "对话框标题"));

			
			

4.8.2. 分享图片

			
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*"); //设置MIME类型
intent.putExtra(Intent.EXTRA_STREAM, uri); //需要分享的文件URI
startActivity(Intent.createChooser(intent, "对话框标题"));
			
			

分享多张图片

			
ArrayList<Uri> imageUris = new ArrayList<>();
imageUris.add(uri);
imageUris.add(uri);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "对话框标题"));			
			
			

4.8.3.