2017-01-17 1 views
0

나는 나는 다음과 같은 코드를 사용하여 이미지의 ID를 검색 할 수 있다는 사실을 알고 : 궁금파일 경로가있는 경우 MediaStore에서 이미지를 가져온 날짜를 얻는 방법은 무엇입니까?

String[] projection = { MediaStore.Images.Media._ID }; 

    String selection = MediaStore.Images.Media.DATA + " = ?"; 
    String[] selectionArgs = new String[] { mediaFile.mediaFile().getAbsolutePath() }; 

    Uri queryUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 
    ContentResolver contentResolver = context.getContentResolver(); 
    Cursor cursor = contentResolver.query(queryUri, projection, selection, selectionArgs, null); 
    if(cursor!=null) { 
     if (cursor.moveToFirst()) { 
      long id = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID)); 
     } 
     cursor.close(); 
    } 

, 동일한 방법을 사용하여 MediaStore.Images.Media.DATA_TAKEN, MediaStore.Images.Media.LONGITUDEMediaStore.Images.Media.LATITUDE에 어떤 가능한 방법이 있는지?

답변

0

하면 파일 경로를 제공, 당신은 일을 이런 식으로 얻을 수 있습니다 :

File file = new File(filePath); 
if(file.exists()) //Extra check, Just to validate the given path 
{ 
    Date lastModDate = new Date(file.lastModified());  
    Log.i("Dated : "+ lastModDate.toString());//Dispaly lastModDate. You can do/use it your own way 
} 

또 다른 옵션이 이미지의 EXIF 데이터에서 것이다 찾을 수를 사용 가능한 경우 :

ExifInterface intf = null; 
try 
{ 
    intf = new ExifInterface(path); 
} 
catch(IOException e) 
{ 
    e.printStackTrace(); 
} 

if(intf != null) 
{ 
    String dateString = intf.getAttribute(ExifInterface.TAG_DATETIME); 
    Log.i("Dated : "+ dateString.toString()); //Dispaly dateString. You can do/use it your own way 
} 
관련 문제