如何在android中共享文件

我创建了一个应用程序,将发送一个文件使用行动发送,一小时后我的代码不起作用。

当它打开另一个应用程序时,我得到一个错误“传输这样的内容类型不支持”shareIt和蓝牙文件iamafile没有发送到…这是我的代码,我试了很多代码,但不工作。 请帮助

File root = new File(Environment.getExternalStorageDirectory(), "/QuizApp/MyAnswer/"+sharedPreferenceUsername +"/"+ editTitle); Uri uri = Uri.fromFile(root); Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("*/*"); intent.putExtra(Intent.EXTRA_STREAM, uri); startActivity(intent); 

顺便说一句editTitle是一个文件。

我有这个工作多个视频文件。 你可以改变一些线路,以符合你的需求。

对不起,这是用kotlin写的,但我觉得这是可以理解的。

 val sharingIntent = Intent(Intent.ACTION_SEND_MULTIPLE) val files = ArrayList<Uri>() files.add(<first file URI>) ... files.add(<n th file URI>) //here set the type wanted. I think that */* is a bad idea because the app could catch it even if the type is not good sharingIntent.type = "video/*" sharingIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files) sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) context.startActivity(sharingIntent)