그러냐

Android 내장 메모리의 사진 정보 가져오기 본문

android

Android 내장 메모리의 사진 정보 가져오기

관절분리 2016. 5. 16. 09:58
반응형

AndroidManifest.xml 에서 Permission 설정

1.<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
2.<uses-permission android:name="android.permission.WRITE_OWNER_DATA"></uses-permission>
3.<uses-permission android:name="android.permission.READ_OWNER_DATA"></uses-permission>


Main.java


 

001.package com.eg.giver;
002. 
003.import java.util.ArrayList;
004. 
005.import android.app.Activity;
006.import android.database.Cursor;
007.import android.os.Bundle;
008.import android.provider.MediaStore.Images;
009. 
010.public class Main extends Activity
011.{
012.    ArrayList<string> mTitleArray;
013.     
014.    @Override
015.    public void onCreate(Bundle savedInstanceState) {
016.        super.onCreate(savedInstanceState);
017.        setContentView(R.layout.main);
018.         
019.        mTitleArray = new ArrayList<string>();
020.         
021.        getImages ();
022.    }
023.     
024.    public void getImages ()
025.    {
026.        Cursor mManagedCursor;
027.         
028.        mManagedCursor = getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI , null, null, null, null) ;
029.         
030.        if(mManagedCursor != null)
031.        {
032.            mManagedCursor.moveToFirst();
033.             
034.            int nSize = mManagedCursor.getColumnCount();
035.             
036.            while (true)
037.            {
038.                String bucket_display_name =
039.                    mManagedCursor.getString(
040.                            mManagedCursor.getColumnIndex(
041.                                    Images.ImageColumns.BUCKET_DISPLAY_NAME)); // 버킷의 이름
042.                String bucket_id =
043.                    mManagedCursor.getString(
044.                            mManagedCursor.getColumnIndex(
045.                                    Images.ImageColumns.BUCKET_ID)); // 버킷 ID
046.                String date_taken =
047.                    mManagedCursor.getString(
048.                            mManagedCursor.getColumnIndex(
049.                                    Images.ImageColumns.DATE_TAKEN)); // 촬영날짜. 1/1000초 단위
050.                String description =
051.                    mManagedCursor.getString(
052.                            mManagedCursor.getColumnIndex(
053.                                    Images.ImageColumns.DESCRIPTION)); // Image에 대한 설명
054.                String is_private =
055.                    mManagedCursor.getString(
056.                            mManagedCursor.getColumnIndex(
057.                                    Images.ImageColumns.IS_PRIVATE)); // 공개 여부
058.                String latitude =
059.                    mManagedCursor.getString(
060.                            mManagedCursor.getColumnIndex(
061.                                    Images.ImageColumns.LATITUDE)); // 위도
062.                String longitude =
063.                    mManagedCursor.getString(
064.                            mManagedCursor.getColumnIndex(
065.                                    Images.ImageColumns.LONGITUDE)); // 경도
066.                String mini_thumb_magic =
067.                    mManagedCursor.getString(
068.                            mManagedCursor.getColumnIndex(
069.                                    Images.ImageColumns.MINI_THUMB_MAGIC)); // 작은 썸네일
070.                String orientation =
071.                    mManagedCursor.getString(
072.                            mManagedCursor.getColumnIndex(
073.                                    Images.ImageColumns.ORIENTATION)); // 사진의 방향. 0, 90, 180, 270
074.                String picasa_id =
075.                    mManagedCursor.getString(
076.                            mManagedCursor.getColumnIndex(
077.                                    Images.ImageColumns.PICASA_ID)); // 피카사에서 매기는 ID
078.                String id =
079.                    mManagedCursor.getString(
080.                            mManagedCursor.getColumnIndex(
081.                                    Images.ImageColumns._ID)); // 레코드의 PK
082.                String data =
083.                    mManagedCursor.getString(
084.                            mManagedCursor.getColumnIndex(
085.                                    Images.ImageColumns.DATA)); // 데이터 스트림. 파일의 경로
086.                String title =
087.                    mManagedCursor.getString(
088.                            mManagedCursor.getColumnIndex(
089.                                    Images.ImageColumns.TITLE)); // 제목
090.                String size =
091.                    mManagedCursor.getString(
092.                            mManagedCursor.getColumnIndex(
093.                                    Images.ImageColumns.SIZE)); // 파일의 크기
094.                String mime_type =
095.                    mManagedCursor.getString(
096.                            mManagedCursor.getColumnIndex(
097.                                    Images.ImageColumns.MIME_TYPE)); // 마임 타입
098.                String display_name =
099.                    mManagedCursor.getString(
100.                            mManagedCursor.getColumnIndex(
101.                                    Images.ImageColumns.DISPLAY_NAME)); // 파일 표시명
102.                String date_modified =
103.                    mManagedCursor.getString(
104.                            mManagedCursor.getColumnIndex(Images.ImageColumns.DATE_MODIFIED)); // 최후 갱신 날짜. 초단위
105.                String date_added =
106.                    mManagedCursor.getString(
107.                            mManagedCursor.getColumnIndex(
108.                                    Images.ImageColumns.DATE_ADDED)); // 추가 날짜. 초단위
109.                 
110.                mTitleArray.add(title);
111.                 
112.                if (mManagedCursor.isLast())
113.                {
114.                    break;
115.                }
116.                else
117.                {
118.                    mManagedCursor.moveToNext();
119.                }
120.            }
121.        }
122.         
123.    }
124.}</string></string>

 

 

출처 : http://btd86.tistory.com/104 

 

반응형