android指定分享到qq,Android使用系统分享文件给微信,QQ指定的用户

Android API与Android版本对应关系java

Android API

Android版本

28

Android 9

P

Android  P Preview

27

Android  8.1(Oreo)

26

Android  8.0(Oreo)

25

Android  7.1.1(Nougat)

24

Android  7.0(Nougat)

23

Android  6.0(MarshMallow)

22

Android  5.1(Lollipop)

21

Android  5.0(Lollipop)

20

Android  4.4W(Kitkat Wear)

19

Android  4.4(Kitkat)

18

Android  4.3(Jelly Bean)

17

Android  4.2(Jelly Bean)

16

Android  4.1(Jelly Bean)

15

Android  4.0.3(IceCreamSandwich)

14

Android  4.0(IceCreamSandwich)

13

Android  3.2(Honeycomb)

12

Android  3.1(Honeycomb)

11

Android  3.0(Honeycomb)

String fileName = Environment.getExternalStorageDirectory() + File.separator + "test" + File.separator + inputEntity.getUnit() + ".txt";

Intent shareIntent = new Intent(Intent.ACTION_SEND);

//Android7.0版本以上使用FileProvider

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

shareIntent.putExtra(Intent.EXTRA_STREAM,

FileProvider.getUriForFile(ReviewActivity.this,

GeneralUtils.getPackageName(ReviewActivity.this)

+ ".provider", new File(fileName)));

}else {

shareIntent.putExtra(Intent.EXTRA_STREAM, new File(fileName));

}

shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

shareIntent.setType("*/*");//此处可发送多种文件

shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//这一句必定得写

startActivity(Intent.createChooser(shareIntent, "分享文件"));

AndroidManifest.xml中注册.provider.划重点:android:authorities设置成你的包名+(.provider) ,这里的.provider路径要和上面的.provider路径同样。android:resource="@xml/provider_paths".这个目录以及文件都是须要本身建立的。android

AndroidManifest.xmlide

android:name="android.support.v4.content.FileProvider"

android:authorities="com.example.test.provider"

android:exported="false"

android:grantUriPermissions="true">

android:name="android.support.FILE_PROVIDER_PATHS"

android:resource="@xml/provider_paths"/>

子节点

对应路径

例子

files_path

Context.getFilesDir()

cache_path

Context.getCacheDir()

external_path

Environment.getExternalStorageDirectory()

/storage/emulated/0/

external_files_path

Context.getExternalFilesDir()

externa_cache_path

Context.getExternalCacheDir()

@xml/provider_pathsui

个人文件路径是Environment.getExternalStorageDirectory() ,因此paths子节点name是external_path. path = "test"是你文件存放的路径,/storage/emulated/0/是虚拟目录,实际上的路径是手机存储/test/xxx.txt。this

路径没写对,分享的时候会报“获取资源失败”。spa

以上就是使用系统的分享文件到各平台的方法。code

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值