Android 9 (Pie) ContentResolver query MediaStore.Images.Media.EXTERNAL_CONTENT_URI returns null on api 28
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am fetching list of all the images, videos and audio files in the device. The below code is working fine on all devices up till android O (api 27). But it is not working on android Pie devices (api 28). Cursor
returns null for the query
For Images
String proj = MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.TITLE,
MediaStore.Images.Media.SIZE
;
ContentResolver cr = context.getContentResolver();
Cursor imagescursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
proj, null, null, "_size DESC");
For Video files
String proj = MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.TITLE,
MediaStore.Video.Media.SIZE,
MediaStore.Video.Media.DURATION
;
ContentResolver cr = context.getContentResolver();
Cursor videocursor = context.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
proj, null, null, "_size DESC");
For Audio files
String proj = MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.SIZE,
MediaStore.Audio.Media.DURATION;
ContentResolver cr = context.getContentResolver();
Cursor audiocursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj, null, null, "_size DESC");
Please if anyone can help me out!
android media-queries android-contentresolver mediastore android-9.0-pie
add a comment |
I am fetching list of all the images, videos and audio files in the device. The below code is working fine on all devices up till android O (api 27). But it is not working on android Pie devices (api 28). Cursor
returns null for the query
For Images
String proj = MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.TITLE,
MediaStore.Images.Media.SIZE
;
ContentResolver cr = context.getContentResolver();
Cursor imagescursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
proj, null, null, "_size DESC");
For Video files
String proj = MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.TITLE,
MediaStore.Video.Media.SIZE,
MediaStore.Video.Media.DURATION
;
ContentResolver cr = context.getContentResolver();
Cursor videocursor = context.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
proj, null, null, "_size DESC");
For Audio files
String proj = MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.SIZE,
MediaStore.Audio.Media.DURATION;
ContentResolver cr = context.getContentResolver();
Cursor audiocursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj, null, null, "_size DESC");
Please if anyone can help me out!
android media-queries android-contentresolver mediastore android-9.0-pie
hey, I'm facing the same problem, have you found a solution to this?
– Goran Horia Mihail
Nov 26 '18 at 20:52
@GoranHoriaMihail check my answer. It might help you.
– Ibrahim Gharyali
Nov 28 '18 at 6:56
add a comment |
I am fetching list of all the images, videos and audio files in the device. The below code is working fine on all devices up till android O (api 27). But it is not working on android Pie devices (api 28). Cursor
returns null for the query
For Images
String proj = MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.TITLE,
MediaStore.Images.Media.SIZE
;
ContentResolver cr = context.getContentResolver();
Cursor imagescursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
proj, null, null, "_size DESC");
For Video files
String proj = MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.TITLE,
MediaStore.Video.Media.SIZE,
MediaStore.Video.Media.DURATION
;
ContentResolver cr = context.getContentResolver();
Cursor videocursor = context.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
proj, null, null, "_size DESC");
For Audio files
String proj = MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.SIZE,
MediaStore.Audio.Media.DURATION;
ContentResolver cr = context.getContentResolver();
Cursor audiocursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj, null, null, "_size DESC");
Please if anyone can help me out!
android media-queries android-contentresolver mediastore android-9.0-pie
I am fetching list of all the images, videos and audio files in the device. The below code is working fine on all devices up till android O (api 27). But it is not working on android Pie devices (api 28). Cursor
returns null for the query
For Images
String proj = MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.TITLE,
MediaStore.Images.Media.SIZE
;
ContentResolver cr = context.getContentResolver();
Cursor imagescursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
proj, null, null, "_size DESC");
For Video files
String proj = MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.TITLE,
MediaStore.Video.Media.SIZE,
MediaStore.Video.Media.DURATION
;
ContentResolver cr = context.getContentResolver();
Cursor videocursor = context.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
proj, null, null, "_size DESC");
For Audio files
String proj = MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.SIZE,
MediaStore.Audio.Media.DURATION;
ContentResolver cr = context.getContentResolver();
Cursor audiocursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj, null, null, "_size DESC");
Please if anyone can help me out!
android media-queries android-contentresolver mediastore android-9.0-pie
android media-queries android-contentresolver mediastore android-9.0-pie
edited Nov 15 '18 at 9:39
Ibrahim Gharyali
asked Nov 15 '18 at 9:13
Ibrahim GharyaliIbrahim Gharyali
489217
489217
hey, I'm facing the same problem, have you found a solution to this?
– Goran Horia Mihail
Nov 26 '18 at 20:52
@GoranHoriaMihail check my answer. It might help you.
– Ibrahim Gharyali
Nov 28 '18 at 6:56
add a comment |
hey, I'm facing the same problem, have you found a solution to this?
– Goran Horia Mihail
Nov 26 '18 at 20:52
@GoranHoriaMihail check my answer. It might help you.
– Ibrahim Gharyali
Nov 28 '18 at 6:56
hey, I'm facing the same problem, have you found a solution to this?
– Goran Horia Mihail
Nov 26 '18 at 20:52
hey, I'm facing the same problem, have you found a solution to this?
– Goran Horia Mihail
Nov 26 '18 at 20:52
@GoranHoriaMihail check my answer. It might help you.
– Ibrahim Gharyali
Nov 28 '18 at 6:56
@GoranHoriaMihail check my answer. It might help you.
– Ibrahim Gharyali
Nov 28 '18 at 6:56
add a comment |
1 Answer
1
active
oldest
votes
So I am able to find a workaround for this. Please let me know if anyone finds a better way to do it.
Step 1. local storage directory path
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
Step 2. For images, Videos, Audios
private ArrayList<File> allShownImagesPath = new ArrayList<>();
private ArrayList<File> allShownVideoPath = new ArrayList<>();
private ArrayList<File> allShownAudioPath = new ArrayList<>();
Step 3. I am calling this method in background thread
public void searchDir(File dir)
//audio
String mp3 = ".mp3";
String ogg = ".ogg";
String aac = ".aac";
//video
String mp4 = ".mp4";
String mkv = ".mkv";
String avi = ".avi";
String webm = ".webm";
//images
String webp = ".webp";
String png = ".png";
String jpg = ".jpg";
String gif = ".gif";
File listFile = dir.listFiles();
if (listFile != null)
for (File file : listFile)
if (file.isDirectory())
if (!file.getName().equals("Android") && !file.isHidden()) // will skip Android folder, hidden folders
searchDir(file);
else
if (!file.isHidden())
Of course you can use more filters to find different files like .pdf
, .docx
, etc.
Not relevant to the question, but you can sort your files.
if (allShownImagesPath.size() > 0)
File sortedImgFiles = allShownImagesPath.toArray(new File[0]);
Arrays.sort(sortedImgFiles, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315937%2fandroid-9-pie-contentresolver-query-mediastore-images-media-external-content-u%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
So I am able to find a workaround for this. Please let me know if anyone finds a better way to do it.
Step 1. local storage directory path
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
Step 2. For images, Videos, Audios
private ArrayList<File> allShownImagesPath = new ArrayList<>();
private ArrayList<File> allShownVideoPath = new ArrayList<>();
private ArrayList<File> allShownAudioPath = new ArrayList<>();
Step 3. I am calling this method in background thread
public void searchDir(File dir)
//audio
String mp3 = ".mp3";
String ogg = ".ogg";
String aac = ".aac";
//video
String mp4 = ".mp4";
String mkv = ".mkv";
String avi = ".avi";
String webm = ".webm";
//images
String webp = ".webp";
String png = ".png";
String jpg = ".jpg";
String gif = ".gif";
File listFile = dir.listFiles();
if (listFile != null)
for (File file : listFile)
if (file.isDirectory())
if (!file.getName().equals("Android") && !file.isHidden()) // will skip Android folder, hidden folders
searchDir(file);
else
if (!file.isHidden())
Of course you can use more filters to find different files like .pdf
, .docx
, etc.
Not relevant to the question, but you can sort your files.
if (allShownImagesPath.size() > 0)
File sortedImgFiles = allShownImagesPath.toArray(new File[0]);
Arrays.sort(sortedImgFiles, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
add a comment |
So I am able to find a workaround for this. Please let me know if anyone finds a better way to do it.
Step 1. local storage directory path
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
Step 2. For images, Videos, Audios
private ArrayList<File> allShownImagesPath = new ArrayList<>();
private ArrayList<File> allShownVideoPath = new ArrayList<>();
private ArrayList<File> allShownAudioPath = new ArrayList<>();
Step 3. I am calling this method in background thread
public void searchDir(File dir)
//audio
String mp3 = ".mp3";
String ogg = ".ogg";
String aac = ".aac";
//video
String mp4 = ".mp4";
String mkv = ".mkv";
String avi = ".avi";
String webm = ".webm";
//images
String webp = ".webp";
String png = ".png";
String jpg = ".jpg";
String gif = ".gif";
File listFile = dir.listFiles();
if (listFile != null)
for (File file : listFile)
if (file.isDirectory())
if (!file.getName().equals("Android") && !file.isHidden()) // will skip Android folder, hidden folders
searchDir(file);
else
if (!file.isHidden())
Of course you can use more filters to find different files like .pdf
, .docx
, etc.
Not relevant to the question, but you can sort your files.
if (allShownImagesPath.size() > 0)
File sortedImgFiles = allShownImagesPath.toArray(new File[0]);
Arrays.sort(sortedImgFiles, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
add a comment |
So I am able to find a workaround for this. Please let me know if anyone finds a better way to do it.
Step 1. local storage directory path
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
Step 2. For images, Videos, Audios
private ArrayList<File> allShownImagesPath = new ArrayList<>();
private ArrayList<File> allShownVideoPath = new ArrayList<>();
private ArrayList<File> allShownAudioPath = new ArrayList<>();
Step 3. I am calling this method in background thread
public void searchDir(File dir)
//audio
String mp3 = ".mp3";
String ogg = ".ogg";
String aac = ".aac";
//video
String mp4 = ".mp4";
String mkv = ".mkv";
String avi = ".avi";
String webm = ".webm";
//images
String webp = ".webp";
String png = ".png";
String jpg = ".jpg";
String gif = ".gif";
File listFile = dir.listFiles();
if (listFile != null)
for (File file : listFile)
if (file.isDirectory())
if (!file.getName().equals("Android") && !file.isHidden()) // will skip Android folder, hidden folders
searchDir(file);
else
if (!file.isHidden())
Of course you can use more filters to find different files like .pdf
, .docx
, etc.
Not relevant to the question, but you can sort your files.
if (allShownImagesPath.size() > 0)
File sortedImgFiles = allShownImagesPath.toArray(new File[0]);
Arrays.sort(sortedImgFiles, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
So I am able to find a workaround for this. Please let me know if anyone finds a better way to do it.
Step 1. local storage directory path
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
Step 2. For images, Videos, Audios
private ArrayList<File> allShownImagesPath = new ArrayList<>();
private ArrayList<File> allShownVideoPath = new ArrayList<>();
private ArrayList<File> allShownAudioPath = new ArrayList<>();
Step 3. I am calling this method in background thread
public void searchDir(File dir)
//audio
String mp3 = ".mp3";
String ogg = ".ogg";
String aac = ".aac";
//video
String mp4 = ".mp4";
String mkv = ".mkv";
String avi = ".avi";
String webm = ".webm";
//images
String webp = ".webp";
String png = ".png";
String jpg = ".jpg";
String gif = ".gif";
File listFile = dir.listFiles();
if (listFile != null)
for (File file : listFile)
if (file.isDirectory())
if (!file.getName().equals("Android") && !file.isHidden()) // will skip Android folder, hidden folders
searchDir(file);
else
if (!file.isHidden())
Of course you can use more filters to find different files like .pdf
, .docx
, etc.
Not relevant to the question, but you can sort your files.
if (allShownImagesPath.size() > 0)
File sortedImgFiles = allShownImagesPath.toArray(new File[0]);
Arrays.sort(sortedImgFiles, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
edited Nov 28 '18 at 10:16
answered Nov 28 '18 at 6:54
Ibrahim GharyaliIbrahim Gharyali
489217
489217
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315937%2fandroid-9-pie-contentresolver-query-mediastore-images-media-external-content-u%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
hey, I'm facing the same problem, have you found a solution to this?
– Goran Horia Mihail
Nov 26 '18 at 20:52
@GoranHoriaMihail check my answer. It might help you.
– Ibrahim Gharyali
Nov 28 '18 at 6:56