title: I could not choose PDF file in Android 8 Oreo (Huawei)
body: <p>I am new to android and I am  trying to choose pdf file to upload to the server in an android application 
  I have a problem with api>24 in Huawei phones 
  I take look for similar problems in StackOverflow but did not solve my problem 
  <a href="https://stackoverflow.com/questions/51546617/in-android-8-oreo-intent-chooser-is-not-working-to-set-wallpaper">like this question </a></p>
  
  <p>this problem just with Huawei's phone 
  I have tried to pick a file from Samsung oreo and everything is okay, 
  but with Huawei, the activity crushed 
  <strong>my code</strong></p>
  
  <pre><code>   private void imageBrowse() {
  
  
  
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) {
          Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
          intent.addCategory(Intent.CATEGORY_OPENABLE);
  
          intent.setType("application/pdf");
          startActivityForResult(Intent.createChooser(intent, "Select Pdf"), PICK_IMAGE_REQUEST);
      }
      else {
          Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
          intent.addCategory(Intent.CATEGORY_OPENABLE);
  
          intent.setType("application/pdf");
        //  intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        //  intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  
        //  intent.setAction(Intent.ACTION_GET_CONTENT);
          startActivityForResult(Intent.createChooser(intent, "Select Pdf"), PICK_IMAGE_REQUEST);
      }
  }
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if (resultCode == RESULT_OK) {
  
          if(requestCode == PICK_IMAGE_REQUEST){
              Uri picUri = data.getData();
  
  
  
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) {
                  filePath = getPath(this,picUri);
  
              }
  
  
              NAME = getPathfromURI(picUri);
              AlertDialog.Builder a_builder = new AlertDialog.Builder(Teacher_upload_files.this);
              a_builder.setMessage("اسم الملف :"+NAME)
                      .setCancelable(false)
                      .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                               fileName.setText(NAME);
                          }
                      });
              AlertDialog alert = a_builder.create();
              alert.setTitle("شكرا :) ");
              alert.show();
  
              Log.d("picUri", picUri.toString());
            //  Log.d("filePath", filePath);
  
           //   imageView.setImageURI(picUri);
  
          }
  
      }
  
  }
  </code></pre>
  
  <p><strong>this is how I get the path</strong></p>
  
  <pre><code>public static String getPath(final Context context, final Uri uri) {
  
      final boolean isKitKat = Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT;
  
      // DocumentProvider
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) {
          if (isKitKat &amp;&amp; DocumentsContract.isDocumentUri(context, uri)) {
              // ExternalStorageProvider
              if (isExternalStorageDocument(uri)) {
                  final String docId = DocumentsContract.getDocumentId(uri);
                  final String[] split = docId.split(":");
                  final String type = split[0];
  
                  if ("primary".equalsIgnoreCase(type)) {
                      return Environment.getExternalStorageDirectory() + "/" + split[1];
                  }
  
                  // TODO handle non-primary volumes
              }
              // DownloadsProvider
              else if (isDownloadsDocument(uri)) {
  
                  final String id = DocumentsContract.getDocumentId(uri);
  
                  final Uri contentUri = ContentUris.withAppendedId(
                          Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
  
                  return getDataColumn(context, contentUri, null, null);
              }
              // MediaProvider
              else if (isMediaDocument(uri)) {
                  final String docId = DocumentsContract.getDocumentId(uri);
                  final String[] split = docId.split(":");
                  final String type = split[0];
  
                  Uri contentUri = null;
                  if ("image".equals(type)) {
                      contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                  } else if ("video".equals(type)) {
                      contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                  } else if ("audio".equals(type)) {
                      contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                  }
  
                  final String selection = "_id=?";
                  final String[] selectionArgs = new String[] {
                          split[1]
                  };
  
                  return getDataColumn(context, contentUri, selection, selectionArgs);
              }
          }
          // MediaStore (and general)
          else if ("content".equalsIgnoreCase(uri.getScheme())) {
              return getDataColumn(context, uri, null, null);
          }
          // File
          else if ("file".equalsIgnoreCase(uri.getScheme())) {
              return uri.getPath();
          }
      }
  
      return null;
  }
  </code></pre>
  
  <p><strong>the problem is here always null</strong></p>
  
  <pre><code>public static String getDataColumn(Context context, Uri uri, String selection,
                                     String[] selectionArgs) {
  
      Cursor cursor = null;
      final String column = "_data";
      final String[] projection = {
              column
      };
  
      try {
          cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                  null);
          if (cursor != null &amp;&amp; cursor.moveToFirst()) {
              final int column_index = cursor.getColumnIndexOrThrow(column);
              return cursor.getString(column_index);
          }
      } finally {
          if (cursor != null)
              cursor.close();
      }
      return null;
  }
  </code></pre>
  
  <p><strong>and this is the error</strong></p>
  
  <pre><code> java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.providers.downloads.documents/document/4736 flg=0x43 }} to activity {com.am.ahmad/com.am.ahmad.Teacher_upload_files}: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/4736
      at android.app.ActivityThread.deliverResults(ActivityThread.java:4932)
      at android.app.ActivityThread.handleSendResult(ActivityThread.java:4975)
      at android.app.ActivityThread.-wrap20(Unknown Source:0)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1950)
      at android.os.Handler.dispatchMessage(Handler.java:108)
      at android.os.Looper.loop(Looper.java:166)
      at android.app.ActivityThread.main(ActivityThread.java:7425)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
   Caused by: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/4736
      at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165)
      at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
      at android.content.ContentProviderProxy.query(ContentProviderNative.java:418)
      at android.content.ContentResolver.query(ContentResolver.java:766)
      at android.content.ContentResolver.query(ContentResolver.java:716)
      at android.content.ContentResolver.query(ContentResolver.java:667)
      at com.am.ahmad.Teacher_upload_files.getDataColumn(Teacher_upload_files.java:593)
      at com.am.ahmad.Teacher_upload_files.getPath(Teacher_upload_files.java:536)
      at com.am.ahmad.Teacher_upload_files.onActivityResult(Teacher_upload_files.java:372)
      at android.app.Activity.dispatchActivityResult(Activity.java:7690)
      at android.app.ActivityThread.deliverResults(ActivityThread.java:4928)
      at android.app.ActivityThread.handleSendResult(ActivityThread.java:4975) 
      at android.app.ActivityThread.-wrap20(Unknown Source:0) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1950) 
      at android.os.Handler.dispatchMessage(Handler.java:108) 
      at android.os.Looper.loop(Looper.java:166) 
      at android.app.ActivityThread.main(ActivityThread.java:7425) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) 
  </code></pre>