我想浏览 sdcard 中的 pdf 文件,然后想在 pdfviewer 中打开它。无论我尝试打开 sdcard 但没有在 pdfviewer 中打开它。
我怎样才能做到这一点?
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();
} }
}
}
}