Declaring MIME type for a "custom file" that is to be Sent via Bluetooth
Asked Answered
C

1

5

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:

     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:

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

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?

Cornered answered 8/5, 2013 at 12:56 Comment(1)
some other questions regarding the same topic: #16413998 #16432838Cornered
A
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"));
Annular answered 28/7, 2013 at 21:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.