蓝牙文件不会被发送错误蓝牙、错误、文件

2023-09-12 08:07:53 作者:作业,我要和你分手

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

 
精彩推荐
图片推荐