【问题标题】:Declaring MIME type for a "custom file" that is to be Sent via Bluetooth为要通过蓝牙发送的“自定义文件”声明 MIME 类型
【发布时间】:2013-05-02 17:19:51
【问题描述】:

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

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

     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 类型?

【问题讨论】:

标签: android bluetooth android-manifest mime-types intentfilter


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-01
    • 2012-02-14
    • 2016-04-25
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多