私が試みているのは、Bluetooth経由でファイルを共有することです。私はACTION_SEND
意図にファイル名を渡す以下の2つの方法を試しました。 share
アクティビティがポップアップしています。接続したBluetoothデバイスに触れると、Bluetooth share: File Unknown file not sent
というトーストを受け取ります。どちらの方法も失敗します。Android NのBluetooth対応のファイルを共有する
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:FILENAME:ヌル
私がチェックしていますアンドロイドのソースコード、このエラーはfilenameがnullの場合に発生します。ログには、filenameがnullであることも示されます。しかし、私は正確な理由を理解することができませんでした。誰かがここで私を助けてください、私のコードで何が間違っていますか?
私に疑問があれば私に通知してください。 –
ありがとう、しかし、これはSDKのバージョン24以上で動作しません。だから私はAndroid Nをその質問に入れているのです。上記のコードの2つの問題 - java.lang.ClassCastException:java.util.ArrayListをandroid.os.Parcelableにキャストできません。 - arraylistのparcellable isnteadを渡してください。次の '原因:android.os.FileUriExposedException:' - Uri.fromFile'を使用できません。 :( – Rilwan