たとえば、Adobe で PDF を読むのが困難です。購入する前に携帯電話にインストールされていたように見える Document Viewer があります (デフォルトの Android アプリだと思いました)。これで、私のコードは正常に動作します。しかし、おそらく Document Viewer を持っていない人がクラッシュするのを見たことがあります。
だから私はアドビリーダーで自分のコードをテストしましたが、クラッシュしました!
誰かが私のコードの何が問題なのかを説明してくれませんか (および/または) ユーザーにダウンロードさせるための Gplay リンクを教えてもらえますか?
public Intent readPdf(String name, int res) {
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, name);
// AssetManager assetManager = getAssets();
InputStream in = null;
try {
// InputStream in = assetManager
// .open("cartecannesplus01pdf.pdf");
in = getResources().openRawResource(res);
OutputStream out = new FileOutputStream(pdfFile);
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ((bufferLength = in.read(buffer)) > 0) {
out.write(buffer, 0, bufferLength);
}
out.flush();
out.close();
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
Uri path = Uri.fromFile(pdfFile);
Intent intent = null;
if (Utils.appInstalledOrNot(me, "com.adobe.reader")) {
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
} else {
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.adobe.reader"));
}
return intent;
}
ありがとう !
ルノー