Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 蓝牙文件未发送错误_Android_File_Bluetooth - Fatal编程技术网

Android 蓝牙文件未发送错误

Android 蓝牙文件未发送错误,android,file,bluetooth,Android,File,Bluetooth,我正在尝试将我在android手机上的应用程序中的文件发送到其他设备(可能是也可能不是android手机) 我发送文件的全部代码是: try{ File dir = getCacheDir(); File f; try { f = File.createTempFile("card", ".Xcard", dir); Intent i = new Intent

我正在尝试将我在android手机上的应用程序中的文件发送到其他设备(可能是也可能不是android手机)

我发送文件的全部代码是:

try{
            File dir = getCacheDir();
            File f;
            try {
                f = File.createTempFile("card", ".Xcard", dir);

                Intent i = new Intent();
                i.setAction(Intent.ACTION_SEND);
                i.setType("*/*");
                i.putExtra(i.EXTRA_STREAM, Uri.fromFile(f));
                startActivity(i);


            } catch (IOException e) {
                // TODO Auto-generated catch block
                Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();

                e.printStackTrace();
            }

            }catch(Exception e){

                Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
            }
但是我的文件没有被发送到电话?? 代码中有什么错误? 是因为接收电话无法识别我的“.Xcard”文件吗

但我认为这不是问题所在 因为我尝试将“apk”文件发送到另一个设备,但它收到了,即使它不理解apk文件。(我正在尝试使用非android手机)

那么为什么我发送的文件没有被发送呢?是因为它是在缓存目录中创建的吗

这对我很有用:

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

区别在于在bluetooth目录中创建文件。

会发生什么?是否出现允许用户选择文件发送位置的活动?可能该文件被忽略,因为它是空的--您是否尝试向其写入内容?不,我没有向其写入任何内容,我将检查它是否与某些内容一起发送。我添加了以下代码:OutputStream op=new FileOutputStream(f);int一字节=1;操作写入(一字节);op.close();但它不工作代码看起来没问题,但会发生什么?活动是否出现?对话?错误消息?什么都没有?我在说“文件名未发送到bluetoothdevicename”时出错