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

Poo*_*eti 4 pdf android android-studio

因为我可以打开下载文件夹,但 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 android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
Run Code Online (Sandbox Code Playgroud)

小智 5

这条鳕鱼对我有用

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/pdf");
startActivityForResult(intent, SAVE_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)