0
在我的android應用程序中,我有一個名爲2pg.pdf的pdf文件,我似乎無法在我的設備的本地應用程序中打開此pdf,我從來沒有之前從資產文件夾中獲得了一個文件,你能告訴我我應該添加到下面的類中嗎?從資產文件夾中獲取pdf文件
public class FullscreenActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen);
Button button = (Button) findViewById(R.id.bPressMe);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
File pdfFile = new File(Environment
.getExternalStorageDirectory(), "/assets/2pg.pdf");
try {
if (pdfFile.exists()) {
Uri path = Uri.fromFile(pdfFile);
Intent objIntent = new Intent(Intent.ACTION_VIEW);
objIntent.setDataAndType(path, "application/pdf");
objIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objIntent);
} else {
Toast.makeText(FullscreenActivity.this, "File NotFound",
Toast.LENGTH_SHORT).show();
}
} catch (ActivityNotFoundException e) {
Toast.makeText(FullscreenActivity.this,
"No Viewer Application Found", Toast.LENGTH_SHORT)
.show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}