声明MIME类型为"自定义文件"即通过蓝牙发送 [英] declaring mime type for a "custom file" that is to be sent via bluetooth
问题描述
我真的需要解决这个问题的帮助:
I really need help in solving this issue:
我开发一个应用程序使用蓝牙我的应用程序到其他手机传输文件。当我想传送一个图像文件,我的code中的一部分去如下:
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.
和Android清单文件去如下:
And the android manifest File went as Follows:
<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>
和code正常工作。现在的问题是: 同样地,我想发送由下面的行中创建的文件:
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());
该文件的名称将是这样的:
The name of the file would be something like this:
card12434247.Xcard
现在哪些修改需要在code,我张贴以上? 我应该如何写在意向过滤器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? Is it required?? Please help!!
推荐答案
尝试把文件中的蓝牙目录中,它为我工作。
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类型为&QUOT;自定义文件&QUOT;即通过蓝牙发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!