2013-05-08 28 views
4

发送我真的需要帮助解决这一问题:声明MIME类型为“自定义文件”,也就是通过蓝牙

我开发的应用程序将文件从我的应用程序转移到利用蓝 - 其他手机齿。当我想传递一个图像文件,我的代码的一部分去如下:

 intent.setType("image/*"); 
    i.putExtra(i.EXTRA_STREAM, uri); 
    //here uri has the URI of the image that I want to send. 

和Android清单文件去如下:

<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> 

和代码工作的罚款。现在的问题是: 同样地,我想送由以下行创建文件:

f = File.createTempFile("card", ".XCard", getExternalCacheDir()); 

该文件的名称将是这样的:

card12434247.Xcard 

现在什么修改我在上面发布的代码中是否需要? 我该如何在意向过滤器中编写mimeType?

应该是什么线:

intent.setType(...)? 

我应该如何修改它,使蓝牙将能够处理这个文件

xyz.Xcard ?? 

我应该如何申报自定义MIME类型,这将是需要发送我的文件通过蓝牙发送? 是否需要? 请帮忙!!

+0

关于同一主题的一些其他问题:http://stackoverflow.com/questions/16413498/blue-tooth-file-not-sent-error http://stackoverflow.com/questions/16432338/发送文件,使用默认蓝牙应用功能于安卓 – neerajDorle 2013-05-09 17:02:11

回答

0

试着把文件放在蓝牙目录中,它对我有用。

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"));