小编Poo*_*eti的帖子

如何允许用户在android中仅从内部和外部存储器中选择pdf文件

因为我可以打开下载文件夹,但 PDF 看起来像是禁用的,所以我无法选择 PDF 文件。有没有其他方法可以实现这一目标?

这是按钮单击的代码

case R.id.pdf_Upload:
               Intent intent = new Intent();
            intent.setType("pdf/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Pdf"), REQUESTCODE_PICK_Pdf);

            break; 

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {

    case REQUESTCODE_PICK_Pdf:
                if (requestCode == REQUESTCODE_PICK_Pdf && resultCode == RESULT_OK
                        && null != data) {
                    Uri selectedPdf = data.getData();

                    PdfSelected.setVisibility(View.VISIBLE);
                    if (selectedPdf.getLastPathSegment().endsWith("pdf")) {


                        System.out.println("Uri of selected pdf---->" + selectedPdf.toString());
                    } else if (resultCode == RESULT_CANCELED){
                        Toast.makeText(this, "Invalid file type", Toast.LENGTH_SHORT).show();
                    }
                }
    }
Run Code Online (Sandbox Code Playgroud)

权限

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission …
Run Code Online (Sandbox Code Playgroud)

pdf android android-studio

4
推荐指数
1
解决办法
7032
查看次数

4
推荐指数
1
解决办法
2854
查看次数

标签 统计

android ×2

android-studio ×1

font-awesome ×1

pdf ×1