0
未処理のフォルダからsdcardにファイルをコピーしようとしていますが、動作しません。ファイルはファイルマネージャーに表示されません。また、私が(インテント経由で)パスを指定したプログラムもそれを見つけることはできません。これは私が、私がしようとした後ファイルをsdcardにコピーする
private void CopyAssets() throws IOException {
String path = Environment.getExternalStorageDirectory() + "/jazz.pdf";
InputStream in = getResources().openRawResource(R.raw.jazz);
FileOutputStream out = new FileOutputStream(path);
byte[] buff = new byte[1024];
int read = 0;
try {
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
} finally {
in.close();
out.close();
}
}
...
try {
CopyAssets();
} catch (IOException e1) {
e1.printStackTrace();
}
String aux = Environment.getExternalStorageDirectory() + "/jazz.pdf";
Uri path = Uri.parse(aux);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(bgn1.this, "No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
あなたは用途許可android.permission.WRITE_EXTERNAL_STORAGEに@SadeshkumarPeriyasamyのコメントあたり –
チェック権限を与えています。また、 'FileOutputStream out = new FileOutputStream(new File(Environment.getExternalStorageDirectory()、" /jazz.pdf "))' –
@SadeshkumarPeriyasamyを使用して出力パスを作成してみてください。私のアンドロイドマニフェストで: –
user1123530