Skip to content Skip to sidebar Skip to footer

Action_get_content Picking Document From Downloads Returns Null

I am working on PDF pick and upload to server. Below code crashed when file picked from Downloads. And works fine if file choose from any other directory. I have tried below code o

Solution 1:

I used use below code for

if (isDownloadsDocument(uri)) {
                StringfileName= getFilePath(context, uri);
                if (fileName != null) {
                    return Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName;
                }

                finalStringid= DocumentsContract.getDocumentId(uri);
                finalUricontentUri= ContentUris.withAppendedId(
                        Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
                return getDataColumn(context, contentUri, null, null);
            }

And getFilePath()

publicstatic String getFilePath(Context context, Uri uri) {

        Cursorcursor=null;
        final String[] projection = {
                MediaStore.MediaColumns.DISPLAY_NAME
        };

        try {
            cursor = context.getContentResolver().query(uri, projection, null, null,
                    null);
            if (cursor != null && cursor.moveToFirst()) {
                finalintindex= cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME);
                return cursor.getString(index);
            }
        } finally {
            if (cursor != null)
                cursor.close();
        }
        returnnull;
    }

refer: This link

Post a Comment for "Action_get_content Picking Document From Downloads Returns Null"