Skip to content

Instantly share code, notes, and snippets.

@zhaochunqi
Last active August 29, 2015 14:01
Show Gist options
  • Save zhaochunqi/728ee73af5074b14ce5f to your computer and use it in GitHub Desktop.
Save zhaochunqi/728ee73af5074b14ce5f to your computer and use it in GitHub Desktop.
利用Intent分享。
public void shareTo(View view) {
Intent intent = new Intent(Intent.ACTION_SEND);
File file = new File("/storage/sdcard0/DCIM/100_CFV5/DSC_0005.JPG");//写死了一个地址。
// intent.setType("text/plain;image/*");
// intent.putExtra(Intent.EXTRA_SUBJECT,"分享");
// intent.putExtra(Intent.EXTRA_TEXT, "I would like to share this with you...");
// intent.putExtra(Intent.);
// Intent sendIntent = new Intent();
// sendIntent.setAction(Intent.ACTION_SEND);
// sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
// sendIntent.setType("text/plain");
// startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
intent.setType("image/*,text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT,"分享");
intent.putExtra(Intent.EXTRA_TEXT, "I would like to share this with you...");
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(file));
String title = getResources().getString(R.string.chooser_title);
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment