send file using default bluetooth application in android

夙愿已清 提交于 2019-12-13 03:38:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!