为“自定义文件"声明 MIME 类型将通过蓝牙发送 [英] Declaring MIME type for a "custom file" that is to be Sent via Bluetooth
问题描述
我真的需要帮助来解决这个问题:
I really need help in solving this issue:
我正在开发一个应用程序,以使用蓝牙将文件从我的应用程序传输到其他手机.当我想传输一个图像文件时,我的部分代码如下:
I am developing an application to transfer a file from my application to other phone using Blue-tooth. When I wanted to transfer an image file, the part of my code went as follows:
intent.setType("image/*");
i.putExtra(i.EXTRA_STREAM, uri);
//here uri has the URI of the image that I want to send.
安卓清单文件如下:
<intent-filter>
<action android:name="android.intent.action.MAIN"
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:mimeType="image/*" />
<data android:host="*" />
</intent-filter>
代码运行良好.现在我的问题是:同样,我想发送一个由以下行创建的文件:
And code worked fine. Now my question is : Similarly I want to send a file that is created by the following line:
f = File.createTempFile("card", ".XCard", getExternalCacheDir());
文件名应该是这样的:
card12434247.Xcard
现在需要对我上面发布的代码进行哪些修改?我应该如何在意图过滤器中编写 mimeType?
Now what modifications are required in the code that I posted above? How should I write the mimeType in the intent-filter?
应该是什么线:
intent.setType(...)?
我应该如何修改它以便蓝牙能够处理这个文件
How should I modify it so that bluetooth will be able to handle this file
xyz.Xcard ??
我应该如何声明通过蓝牙发送我的文件所需的自定义 mime 类型?
How should I declare the custom mime type that will be required to send my file to be sent via Blue-tooth?
推荐答案
尝试将文件放在蓝牙目录中,它对我有用.
Try to put the file in the bluetooth directory, it worked for me.
String root = Environment.getExternalStorageDirectory().toString();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/html");
File f = new File(root + "/bluetooth/test2.html");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
startActivity(Intent.createChooser(i, "Send page"));
这篇关于为“自定义文件"声明 MIME 类型将通过蓝牙发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!