나는이 갤러리를 통해 휴대폰 갤러리의 내용을 읽고 내용을 임의로 스크롤 할 수 있습니다.폴더의 내용을 임의로 읽음
public static Uri getRandomImage(ContentResolver resolver) {
String[] projection = new String[] {
BaseColumns._ID
};
Random rand = new Random();
int p = 2 + rand.nextInt(8-2+1);
Uri uri = p == 0 ? Media.EXTERNAL_CONTENT_URI : Media.EXTERNAL_CONTENT_URI;
Cursor cursor = Media.query(resolver, uri, projection, null, MediaColumns._ID);
if (cursor == null || cursor.getCount() <= 0) {
return null;
}
cursor.moveToPosition(new Random().nextInt(cursor.getCount()));
return Uri.withAppendedPath(uri, cursor.getString(0));
}
그러나이 코드를 수정하여 나로 설정된 폴더의 내용을 읽으 려합니다. 어떻게해야합니까?
당신에게 아마
http://mattgemmell.com/2008/12/08/what-have-you-tried/? – njzk2
나는 응용 프로그램을 설치하고 시작하자마자 이미 파일 모음을 만든 폴더에 넣었습니다. 게시 된 코드를 다음과 같이 변경하려고했습니다. Uri uri = Uri.parse ("/ sdcard/MyFolder /"); – David
디렉토리에서 파일을 읽으려면 http://android-coding.blogspot.com/2011/10/list-filesdirectory-in-android.html 시작 지점을 지정했습니다. 이것으로부터, 파일을 배열에 배치함으로써 임의의 파일을 쉽게 얻을 수 있습니다. – ariefbayu