其他分享
首页 > 其他分享> > android – 声明mime类型为“自定义文件”,将通过蓝牙发送

android – 声明mime类型为“自定义文件”,将通过蓝牙发送

作者:互联网

我真的需要帮助来解决这个问题:

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

     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

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

应该是什么线:

  intent.setType(...)?

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

  xyz.Xcard ??

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

解决方法:

尝试将文件放在蓝牙目录中,它对我有用.

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

标签:android,android-manifest,intentfilter,mime-types
来源: https://codeday.me/bug/20190927/1824375.html