Android:正确处理蓝牙接收的文件

发布于 2024-09-17 18:22:26 字数 666 浏览 4 评论 0原文

我有一个处理特定类型文件的 Android 应用程序。它为 MIME 类型和文件名模式注册意图过滤器。这一切在文件管理器中都可以正常工作;我选择一个文件,系统会提示我适用于该文件的操作列表,我的应用程序位于列表中,我选择它并且它可以工作。

但是,当我通过蓝牙将文件发送到设备时,这不起作用。文件被接收并正确下载,但从传输页面选择文件没有任何作用(尽管我仍然可以使用文件管理器在 /sdcard/downloads/bluetooth 中查找下载的文件并从那里运行它)。日志包含:(

V/BluetoothOppUtility(  565): Get data from db:/mnt/sdcard/downloads/bluetooth/foo.appnull00:11:22:33:44:55
E/BluetoothOppUtility(  565): ERROR: Para fileName ==null, or mimetype == null

此处文件的名称是 foo.app。)

看起来它决定该文件没有 MIME 类型并放弃,而不是广播请求基于文件名的匹配的意图。

这是在 HTC Desire 上的 Froyo 上,我知道 HTC 一直在修补蓝牙堆栈(因为原生 Android 不允许将任意文件发送到设备)。有谁知道我怎样才能做到这一点?发送 .jpg 和 .png 文件效果很好...

I have an Android application which handles a particular type of file. It registers intent filters for both the MIME type and the filename pattern. This all works fine from file managers; I select a file, I get prompted with a list of actions applicable to the file, my application is on the list, I select it and it works.

However, this doesn't work when I beam a file to the device via Bluetooth. The file gets received and is correctly downloaded, but selecting the file from the transfer page does nothing (although I can still use a file manager to find the downloaded file in /sdcard/downloads/bluetooth and run it from there). The log contains:

V/BluetoothOppUtility(  565): Get data from db:/mnt/sdcard/downloads/bluetooth/foo.appnull00:11:22:33:44:55
E/BluetoothOppUtility(  565): ERROR: Para fileName ==null, or mimetype == null

(The name of the file here is foo.app.)

It looks like it's deciding that the file has no MIME type and is giving up, rather than broadcasting an intent asking for a filename-based match.

This is on Froyo on an HTC Desire, and I know that HTC have been tinkering with the Bluetooth stack (as stock Android doesn't allow arbitrary files to be beamed to the device). Does anyone know how I can make this work? Beaming .jpg and .png files works fine...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

差↓一点笑了 2024-09-24 18:22:26

调查显示,如果蓝牙堆栈未从发送方接收到 MIME 类型,则会使用 android.webkit.MimeTypeMap 类确定 MIME 类型。此类有一个硬编码的扩展名和 MIME 类型表。这意味着如果不向 Google 发送补丁并等待下一个版本,则无法注册其他扩展。

Investigation reveals that the Bluetooth stack, if it doesn't receive a MIME type from the sender, determines the MIME type by using the android.webkit.MimeTypeMap class. This class has a hard-coded table of extensions and MIME types. This means that it's not possible to register additional extensions without sending patches to Google and waiting for the next release.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文