声明要通过蓝牙发送的“自定义文件”的mime类型

时间:2021-01-03 21:22:23

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:

我正在开发一个应用程序,使用Blue-tooth将文件从我的应用程序传输到其他手机。当我想传输图像文件时,我的代码部分如下:

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

And the android manifest File went as Follows:

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

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

Now what modifications are required in the code that I posted above? How should I write the mimeType in the intent-filter?

现在我在上面发布的代码中需要进行哪些修改?我应该如何在intent-filter中编写mimeType?

what should be the line:

应该是什么线:

  intent.setType(...)?

How should I modify it so that bluetooth will be able to handle this file

我该如何修改它以便蓝牙能够处理这个文件

  xyz.Xcard ??

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

我应该如何声明发送我的文件以通过Blue-tooth发送所需的自定义mime类型?需要吗?请帮忙!!

1 个解决方案

#1


0  

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

#1


0  

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