【问题标题】:File transfer via bluetooth fails通过蓝牙传输文件失败
【发布时间】:2013-11-10 13:17:36
【问题描述】:

我正在使用以下简单代码通过蓝牙将文本文件传输到其他设备:

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.setPackage("com.android.bluetooth");
sharingIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(path));
activity.startActivity(Intent.createChooser(sharingIntent,ctx.getResources().getString(R.string.send_pubkey)));

“路径”是要传输的文件的完整路径(并且有效)。当我尝试发送文件时,我收到一条消息,“未知文件”无法传输。那么......这里有什么问题?为什么这个文件未知?

谢谢!

【问题讨论】:

标签: android bluetooth mime-types file-transfer


【解决方案1】:
String path="/storage/file.mp4";
        if(path.startsWith("file")||path.startsWith("content")||path.startsWith("FILE")||path.startsWith("CONTENT")){

        }else{
            path="file://"+path;
        }
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
        shareIntent.setType("video/mp4");
        startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.sendTo)));

【讨论】:

    【解决方案2】:

    您选择的文件路径包含一些额外的字符串,例如 Content:,File: 等。尝试从文件中删除那些不需要的字符串。希望能解决你的问题

    【讨论】:

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