Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by 1612431 ( 7 years ago )
public ArrayList<JDate> getImageByDate(){
        try {
            ArrayList<JDate> listImageByDate = new ArrayList<>();
            Uri uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            String[] projection = {MediaStore.MediaColumns.DATA};
            Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);

            while (cursor.moveToNext()) {
                String absolutePathOfImage = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA));
                File f = new File(absolutePathOfImage);

                boolean exist = false;
                for (int i = 0; i < listImageByDate.size(); i++)
                {
                    if (listImageByDate.get(i).getDate().getMonth() == (new Date(f.lastModified())).getMonth()
                            && listImageByDate.get(i).getDate().getYear() == (new Date(f.lastModified())).getYear())
                    {
                        listImageByDate.get(i).getFileImage().add(f);
                        exist = true;
                        break;
                    }
                    Collections.sort(listImageByDate.get(i).getFileImage());
                }
                if (!exist)
                {
                    JDate jdate = new JDate();
                    Date date = new Date(f.lastModified());
                    jdate.setDate(date);
                    jdate.getFileImage().add(f);
                    listImageByDate.add(jdate);
                }
            }

            for (int i = 0; i < listImageByDate.size() - 1; i++)
            {
                for (int j = i + 1; j <listImageByDate.size(); j++)
                {
                    if (listImageByDate.get(i).getDate().compareTo(listImageByDate.get(j).getDate()) > 0)
                    {
                        Collections.swap(listImageByDate,i,j);
                    }
                }
            }

            return listImageByDate;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

 

Revise this Paste

Parent: 98746
Your Name: Code Language: