【问题标题】:Blue-tooth file not sent error蓝牙文件未发送错误
【发布时间】:2013-05-01 01:54:08
【问题描述】:

我正在尝试将文件从我在 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文件也收到了。 (我正在尝试使用非安卓手机)。

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

【问题讨论】:

  • 会发生什么?是否出现允许用户选择将文件发送到何处的活动?也许该文件被忽略了,因为它是空的——你尝试过向它写入内容吗?
  • 不,我没有写任何内容,我会检查它是否带有一些内容。
  • 我添加了这段代码:OutputStream op = new FileOutputStream(f); int oneByte = 1; op.write(oneByte); op.close();但它不工作
  • 代码看起来没问题——但是发生了什么?是否出现活动?对话?错误信息?什么都没有?
  • 我收到一条错误消息,提示“文件文件名未发送到蓝牙设备名称”

标签: android file bluetooth


【解决方案1】:

这对我有用:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-23
    • 2012-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    相关资源
    最近更新 更多