android分享功能
1.分享bitmap:java://将mipmap中图片转换成UriUri imgUri = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), bitmapByUrl, null,null));Intent shareIntent = new Intent();shareIntent.setAction(Inte
·
1.分享bitmap:
java:
//将mipmap中图片转换成Uri
Uri imgUri = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), bitmapByUrl, null,null));
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
//其中imgUri为图片的标识符
shareIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
shareIntent.setType("image/*");
//切记需要使用Intent.createChooser,否则会出现别样的应用选择框,您可以试试
shareIntent = Intent.createChooser(shareIntent, "Here is the title of Select box");
startActivity(shareIntent);
AndroidManifest.xml的application中添加
<!--分享
//注意和上面FileProvider方法中声明的authorities保持一致
-->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.yongdaimi.android.fileprovider1"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths_share_img" />
xml:新建一个xml,写file_paths_share_img
<?xml version="1.0" encoding="utf-8"?>
<resource xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="images"
path="DCIM/IMAGE" />
</resource>
更多推荐
已为社区贡献17条内容
所有评论(0)