如何以编程方式在Android中共享文件 [英] How to share a file in Android programmatically

查看:96
本文介绍了如何以编程方式在Android中共享文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用共享意图共享文件(.pdf,.apk等),我搜索了google,但我只找到了共享图像的代码

I want to share a file(.pdf,.apk etc) using share Intent, I searched google but I find only the code for sharing Image

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));

推荐答案

您使用相同的代码,只是将MIME类型更改为希望共享的数据类型.如果您希望共享任何类型的内容,请使用*/*

You use the same code, you just change the MIME type for the type of data you wish to share. If you wish to share anything regardless of type, use */*

这篇关于如何以编程方式在Android中共享文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆