问题
I want to send a file from my phone to other phone using my Android application. The File is of type ".Xcard". I want to make use of the default Bluetooth Application provided by the android environment. That is, when I click on send , the default application chooser should open and then I should be able to send the File to other device bu selecting the device. How should I do it? The file may or may not be empty
I have tried the following code but its not working. I get a toast message saying :File was not sent"
f = File.createTempFile("card", ".Xcard", getCacheDir());
FileWriter fw = new FileWriter(f);
BufferedWriter w = new BufferedWriter(fw);
w.write("hello my name is neeraj");
w.close();
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.setType("*/*");
i.putExtra(i.EXTRA_STREAM, Uri.fromFile(f));
startActivity(i);
Please help me out, I am kind of Stuck
回答1:
From the API docs:
public abstract File getCacheDir ()
Returns the absolute path to the application specific cache directory on the filesystem.
(emphasis mine)
The directory returned by getCacheDir()
is only readable by your application, use getExternalCacheDir()
instead.
来源:https://stackoverflow.com/questions/16432338/send-file-using-default-bluetooth-application-in-android