使用android系统中默认的蓝牙应用程序发送的文件 [英] send file using default bluetooth application in android
问题描述
我想用我的Android应用程序从我的手机发送一个文件给其他手机。该文件类型.Xcard的。我想利用的是Android环境提供的默认蓝牙应用。也就是说,当我点击发送,默认的应用程序选择器应该打开,然后我应该能够将文件发送到其他设备BU选择设备。
我应该怎么办呢?该文件可能是或不是空的
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
我曾尝试以下code,但它不工作。我得到一个敬酒消息说:文件未送出
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);
请帮我出,我有点卡住
推荐答案
从API文档:
公共抽象文件getCacheDir()
public abstract File getCacheDir ()
返回在特定应用的绝对路径上的文件系统缓存目录。
(重点煤矿)
按返回目录getCacheDir()
只是读取您的应用程序,使用 getExternalCacheDir()
代替。
The directory returned by getCacheDir()
is only readable by your application, use getExternalCacheDir()
instead.
这篇关于使用android系统中默认的蓝牙应用程序发送的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!