If you want to open your folder assets
try something like this:
private void readFromAssets(String filename) {
AssetManager assetManager = getAssets();
InputStream in = null;
OutputStream out = null;
File file = new File(getFilesDir(), filename);
try {
in = assetManager.open("abc.pdf");
out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e) {
Log.e("erro", e.getMessage());
}
Intent target = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse("file://" + getFilesDir() + "/" + filename),
"application/pdf");
Intent intent = Intent.createChooser(target, "Abrir arquivo");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
//Caso o usuário não tenha um visualizador de PDF, instrua-o aqui a baixar
}
}
If you want to open from the device root, try:
private void readFromExternalStorage(String filename){
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ filename);
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(file), "application/pdf");
Intent intent = Intent.createChooser(target, "Abrir arquivo");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
//Caso o usuário não tenha um visualizador de PDF, instrua-o aqui a baixar
}
}