Skip to content

Instantly share code, notes, and snippets.

@laomo
Last active December 11, 2015 22:39
Show Gist options
  • Save laomo/4671574 to your computer and use it in GitHub Desktop.
Save laomo/4671574 to your computer and use it in GitHub Desktop.
完美实现同时分享图片和文字(Intent.ACTION_SEND)
private void share(String content, Uri uri){
Intent shareIntent = new Intent(Intent.ACTION_SEND);
if(uri!=null){
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("image/*");
//当用户选择短信时使用sms_body取得文字
shareIntent.putExtra("sms_body", content);
}else{
shareIntent.setType("text/plain");
}
shareIntent.putExtra(Intent.EXTRA_TEXT, content);
//自定义选择框的标题
//startActivity(Intent.createChooser(shareIntent, "邀请好友"));
//系统默认标题
startActivity(shareIntent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment