私は生のフォルダからpdfをsdcardに渡して、デフォルトのインテントでオープンしようとしています。アセットからsdcardにpdfを渡す
私はそれを開くと、pdfがダメージを受けていると言われています。私はストリームがどのように働いているかをあまり理解していないので、そこに問題があると思います。
final String extStorageDirectory = Environment
.getExternalStorageDirectory().toString();
final String festivalDirectory_path = extStorageDirectory
+ Constants.PDF_STORAGE_PATH;
File pdfOutputFile = new File(festivalDirectory_path, "/");
if (pdfOutputFile.exists() == false) {
pdfOutputFile.mkdirs();
}
File pdfFile = new File(pdfOutputFile, nameOfThePdf);
try {
InputStream in = getResources().openRawResource(R.raw.blablublo);
FileOutputStream out = new FileOutputStream(pdfFile);
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ((bufferLength = in.read(buffer)) > 0) {
out.write(buffer, 0, bufferLength);
}
out.close();
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
Uri path = Uri.fromFile(pdfFile);
// Uri path = Uri.parse(Constants.SPLASH_URI + R.raw.cartecannotpdf);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
誰かが私を助けてくれることを願っています!あなたのソリューションが半分終わっているよう
THX
ルノー
ファイルをコピーしていません。 http://stackoverflow.com/a/4530294/1321873 – Rajesh
thxを見て、このリンクを見て、私のコードを変更しましたが、何かが恋しいです。 –
今問題は何ですか?問題を特定してみてください - コピーしたファイルを読むことができるかどうかを確認してください(たとえば、コンピュータにダウンロードするなど)。 – Rajesh