使用以下代码可以很好的完成同时分享图片和文字的功能:
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);
}

本文介绍了一种在Android应用中实现图文分享的方法。通过Intent.ACTION_SEND意图和服务类型设置,该方法能够根据图片是否存在来调整分享的内容类型,并确保文字信息始终被包含。
1760

被折叠的 条评论
为什么被折叠?



