我正在使用以下简单代码通过蓝牙将文本文件传输到其他设备:
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)));
“路径”是要传输的文件的完整路径(且有效)。当我尝试发送文件时,我收到一条消息,“未知文件”无法传输。那么...这里出了什么问题?为什么这个文件未知?
谢谢!
最佳答案
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)));
关于android - 通过蓝牙传输文件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19691186/