0

I am new to android development here and I want to open internal memory from my app. But it is open on all devices except Samsung device. It's showing fine on Motorola device, other phones and in Emulator also. I am getting null here: if (scanFolder == null) {return null;}

 public List<Folder> loadInBackground() {
        List<Folder> folderList = new ArrayList<>();
        List<Song> songList = new ArrayList<>();
        // Permission Check Runtime For M and above
        if (PermissionChecker.checkCallingOrSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED) {
            FileExtensionFilter mFileExtensionFilter = new FileExtensionFilter(Constants.fileExtensions);
            if (dir != null) {
                File[] scanFolder = dir.listFiles(mFileExtensionFilter);

                // Getting Null over here in Samsung Device scanFolder getting null
                if (scanFolder == null) {
                    return null;
                }
                // Get Folder List
                for (File aScanFolder : scanFolder) {
                    Folder folder = new Folder();
                    Cursor cursor = getContext().getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Audio.Media.DATA}, MediaStore.Audio.Media.DATA + " like ? ", new String[]{"%" + aScanFolder.getAbsolutePath() + "%"}, null);
                    if (cursor != null) {
                        int count = cursor.getCount();
                        if (count != 0) {
                            if (!aScanFolder.isDirectory()) {
                                String path = aScanFolder.getAbsolutePath();
                                Song song = Helper.getSongData(Extras.getInstance().getSongSortOrder(), getContext(), path);
                                songList.add(song);
                            }
                            if (!aScanFolder.getAbsolutePath().startsWith("/d")) {
                                Log.e("FolderLoader", "Path --> " + aScanFolder.getAbsolutePath());
                                folder.setFile(aScanFolder);
                                folder.setFileCount(count);
                                folder.setSongList(songList);
                                folderList.add(folder);
                            }
                        }
                    }
                    if (cursor != null) {
                        cursor.close();
                    }
                }
                Collections.sort(folderList, new Comparator<Folder>() {
                    @Override
                    public int compare(Folder f1, Folder f2) {
                        if ((f1.getFile().isDirectory() && f2.getFile().isDirectory()))
                            return f1.getFile().getName().compareToIgnoreCase(f2.getFile().getName());
                        else if (f1.getFile().isDirectory() && !f2.getFile().isDirectory())
                            return -1;
                        else if (!f1.getFile().isDirectory() && f2.getFile().isDirectory())
                            return 1;
                        else if (!f1.getFile().isDirectory() && !f2.getFile().isDirectory())
                            return f1.getFile().getName().compareToIgnoreCase(f2.getFile().getName());
                        else return 0;
                    }

                });
                if (!dir.getAbsolutePath().equals("/")) {
                    Folder folder = new Folder();
                    if (dir.getParentFile() != null) {
                        folder.setFile(dir.getParentFile());
                        Log.e("FolderLoader", dir.getParentFile().getAbsolutePath());
                        folderList.add(0, folder);
                    }
                }
            }

            return folderList;
        } else {
            // Error Message
            Log.d("Folder", "Permission not granted");
            return Collections.emptyList();
        }
    } 

Screenshot

I am getting this Screen UI in Samsung Device.

Getting All songs in Other device except Samsung Device

Community
  • 1
  • 1
  • 1
    `I want to open internal memory `. Can you start telling us what you consider to be 'internal memory'? And what 'opening it' would be? Adapt your code so we can see. – greenapps Mar 27 '18 at 07:29
  • I am opening Internal memory songs and songs folder.It's showing all songs and songs folders but showing blank Screen (see attachment) on Samsung Device. I am getting null here: //if (scanFolder == null) {return null;} – Darshan Shah Mar 27 '18 at 07:36
  • Are you unwilling to give decent info? Please adapt your code so we can see full paths. You only repeated yourself. – greenapps Mar 27 '18 at 07:38
  • I have already attach my code please check it – Darshan Shah Mar 27 '18 at 07:41
  • ???? The info i asked for is not in your code. And it is unclear what you attached meanwhile. – greenapps Mar 27 '18 at 07:43
  • @DarshanShah are you looking for a way to get media files ? Do you want their paths? or you looking for the folder paths? – udit7395 Mar 27 '18 at 08:06
  • @udit7395 I am getting media and folder path too Even I can also access internal songs and folder but I can't able to see nothing on Samsung Device(Screenshot attached).I am getting null here: if (scanFolder == null) {return null;}. When I open App in Samsung Device – Darshan Shah Mar 27 '18 at 09:02
  • You still did not tell what you consider to be internal memory. You still did not tell the full path of the folder where you try to list the files. Your code is incomplete as we cannot see what you do. Please adapt your code. – greenapps Mar 27 '18 at 09:21
  • @DarshanShah Please have look at this [pasteBin](https://pastebin.com/4M1VJjgX). If this fixes it let me know I will post is as an answer. – udit7395 Mar 27 '18 at 09:41
  • @udit7395 No Sorry I can't able to fix it – Darshan Shah Mar 27 '18 at 11:02
  • What was output in logs ? – udit7395 Mar 27 '18 at 11:04
  • @udit7395 I am getting Log.d("Folder", "Permission not granted"); this log if I launch an application in Samsung. – Darshan Shah Mar 27 '18 at 13:41
  • @DarshanShah From API 23 (Andriod 6.0) onwards you need to ask user for permissions. Look over here for official [documentation](https://developer.android.com/training/permissions/requesting.html) and here's a stackoverflow [answer](https://stackoverflow.com/questions/33666071/android-marshmallow-request-permission) explaining the same. – udit7395 Mar 27 '18 at 13:55

0 Answers0