Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

android - Declaring MIME type for a "custom file" that is to be Sent via Bluetooth

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...