蓝牙文件未发送错误 [英] Blue-tooth file not sent error

查看:46
本文介绍了蓝牙文件未发送错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to send a file from my application on android phone to other devices (they may or may not be be android phones).

我发送文件的完整代码是:

my whole code for sending the file is :

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"文件?

But my file is not being sent to the phone?? What is wrong in the code? Is it because the receiving phone does not recognize my ".Xcard" file?

但我认为这不是问题因为我尝试将apk"文件发送到另一台设备,即使它不理解该 apk 文件,它也收到了.(我正在尝试使用非安卓手机).

But I don't think that is the problem because i tried sending "apk" file to the other device and it received even though it doesn't understand the apk file. (i am trying with the non-android phone).

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

Then why not the file that I am sending being not-sent? is it because it is created in Cache directory?

推荐答案

这对我有用:

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

区别在于在蓝牙目录下创建文件.

The difference is in create the file in the bluetooth directory.

这篇关于蓝牙文件未发送错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆