I want to browse the sdcard for pdf files and then want open it in pdfviewer. Whatever I tried open the sdcard but doesn't open it in pdfviewer.
How can i do this?
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("application/pdf");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Pdf"), REQUEST_PICK_FILE );
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
case REQUEST_PICK_FILE:
{
Uri data = result.getData();
if(data.getLastPathSegment().endsWith("pdf")){
startActivity(new Intent(this, PDFReaderAct.class));
} else {
Toast.makeText(this, "Invalid file type", Toast.LENGTH_SHORT).show();
} }
}
}
}