我在试图通过蓝牙共享文件。我已经尝试了下面两种方法将文件名传递给ACTION_SEND
打算。 share
活动正在弹出,当我触摸连接的蓝牙设备时,我得到一个敬酒说Bluetooth share: File Unknown file not sent
。这两种方法都失败了。通过蓝牙opp在Android上共享文件N
public void pushFileOverOpp(String filename) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setPackage("com.android.bluetooth");
intent.setType("audio/mp3");
File f = new File(Environment.getExternalStorageDirectory(), "images");
File sample = new File(f, "sample.mp3");
Uri u = Uri.parse(sample.toString());
intent.putExtra(Intent.EXTRA_STREAM, u);
mContext.startActivity(intent);
}
错误,对数似
OppService:URI:/storage/emulated/0/images/sample.mp3 OppService:建议:空 OppService:FILENAME:空 OppService:MIMETYPE:音频/ MP3
File f = new File(mContext.getFilesDir(), "images");
File sample = new File(f, "sample.mp3");
Uri u = FileProvider.getUriForFile(mContext,
BuildConfig.APPLICATION_ID + ".provider", sample);
intent.putExtra(Intent.EXTRA_STREAM, u);
错误,对数
OppService:URI:内容://com.example.com.test.provider/tester/images/sample.mp3 OppService:建议:空 OppService:文件名:空
我已签android源代码,当文件名为空时出现这个错误。日志还说文件名是空的。但我无法弄清楚确切的原因。有人可以请帮我在这里,我的代码有什么问题。
如果你有任何疑问意味着通知我。 –
谢谢,但这不适用于SDK版本24或以上。这就是为什么我把Android N放在问题中。上述代码的两个问题:'java.lang.ClassCastException:java.util.ArrayList不能转换为android.os.Parcelable' - 通过parcellable不是arraylist。下一个'导致:android.os.FileUriExposedException:' - 我们不能使用'Uri.fromFile'。 :( – Rilwan