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

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

问题描述

我想从我的应用程序在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).

我的整个code发送的文件是:

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();
            }

但我的文件不会被发送到手机上? 什么是错的,在code? 难道是因为接收手机不认我.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文件。 (我是用非Android手机尝试)。

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).

那么,为什么不说我发送的文件暂时不发送的?是它,因为它是在高速缓存目录中创建?

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天全站免登陆