我想以某种方式将文件从一台 Android 设备上的应用程序发送到另一台设备上的应用程序。这可以通过任何方式完成,如果您能告诉我如何通过网络发送或类似的东西,我愿意接受建议。
目前,我正在考虑将文件作为电子邮件附件发送,但我还没有找到任何关于如何执行此操作的良好文档。我需要两件事来完成此任务,能够将我的文件(存储在 SD 卡或设备上的某个位置)作为附件发送,并让 Android 将我的应用程序识别为打开带有文件扩展名 (.lst) 的附件的应用程序.
有什么想法吗?
如果有区别的话,这些文件都将是相当小的 xml 文本文件。
最佳答案
I would like to somehow send a file from my app on one android device to my app on another device. This can be done any which way, and I'm open to suggestions if you can tell me how to send over network or something like that.
编写一个 Web 服务。或者使用 Amazon SQS。
be able to send my file (stored on sd card or somewhere on device) as an attachment
如所写here ,你可以尝试:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(Intent.EXTRA_STREAM, ...);
sendIntent.setType(...);
其中第一个省略号是您选择的文件的路径,第二个省略号是合适的 MIME 类型。
and have my app recognized by android as the app to open an attachment with the file extention (.lst)
永远不要依赖文件扩展名。使用 MIME 类型。您可以使用 Intent 过滤器设置 Activity,为您的 MIME 类型提供 ACTION_VIEW
支持。
关于android - 如何从 Android 应用程序发送/打开电子邮件附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2033818/