모바일 기기 내 전체 파일의 각 날짜, 주소 정보 호출 입니다.

일단 '이미지' 파일을 기준으로 작성합니다.

날짜, 주소 외에도 다양한 정보를 호출할 수 있습니다.

 

[ 날짜, 파일 길이, 파일 너비, 휴대폰 만든 회사, 휴대폰 모델명, GPS 등 ]

 

주의 ! 아래 함수는 휴대폰으로 찍은 이미지에 대한 정보만 출력할 수 있습니다.

   //변수 선언부 입니다.

    private boolean valid = false;
    private Float latitude, longitude;
    Geocoder geocoder;

     //onCreate() 혹은 사용하시는 함수에 응용하셔서 함수를 호출하시면 됩니다.

       geocoder = new Geocoder(this);

        String filename = Environment.getExternalStorageDirectory()
                + "/DCIM/Camera/20181214_040001.jpg";
        System.out.println("file path:"+filename);
        try {
            ExifInterface exif = new ExifInterface(filename);
            showExif(exif);
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this, "Error!", Toast.LENGTH_LONG).show();
        }

  

 private void showExif(ExifInterface exif) {

//주소정보 호출을 위한 GPS 정보 호출 변수

        String attrLATITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);

        String attrLATITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);

        String attrLONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);

        String attrLONGITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);

     List list = null;  //Geocoder 객체 + Address 객체를 통해 제공되는 주소 서비스 결과를 리턴함 



        System.out.println("Enter showExif");
        String myAttribute = "[Exif information] \n\n";

        //시간 정보 호출 ->날짜, 시간 정보만 호출한다면 아래 한줄만 사용하시면 됩니다!
        myAttribute += getTagString(ExifInterface.TAG_DATETIME, exif); //날짜 정보 호출부임!!
        System.out.println("날짜"+myAttribute);

        //----------------이 외에도 ExifInterface 함수로 다음과 같은 정보 출력 가능!-----------
        myAttribute += getTagString(ExifInterface.TAG_FLASH, exif);
        myAttribute += getTagString(ExifInterface.TAG_GPS_LATITUDE,
                exif);
        myAttribute += getTagString(
                ExifInterface.TAG_GPS_LATITUDE_REF, exif);
        myAttribute += getTagString(ExifInterface.TAG_GPS_LONGITUDE,
                exif);
        myAttribute += getTagString(
                ExifInterface.TAG_GPS_LONGITUDE_REF, exif);
        myAttribute += getTagString(ExifInterface.TAG_IMAGE_LENGTH,         //이미지 길이 호출
                exif);
        myAttribute += getTagString(ExifInterface.TAG_IMAGE_WIDTH,           //이미지 너비 호출
                exif);
        myAttribute += getTagString(ExifInterface.TAG_MAKE, exif);           //휴대폰 만든 회사
        myAttribute += getTagString(ExifInterface.TAG_MODEL, exif);         //휴대폰 모델명
        myAttribute += getTagString(ExifInterface.TAG_ORIENTATION,
                exif);
        myAttribute += getTagString(ExifInterface.TAG_WHITE_BALANCE,
                exif);


//주소정보 호출 GPS 
        if ((attrLATITUDE != null) && (attrLATITUDE_REF != null) && (attrLONGITUDE != null)
                && (attrLONGITUDE_REF != null)) {
            valid = true;

            if (attrLATITUDE_REF.equals("N")) {
                latitude = convertToDegree(attrLATITUDE);
            } else {
                latitude = 0 - convertToDegree(attrLATITUDE);
            }

            if (attrLONGITUDE_REF.equals("E")) {
                longitude = convertToDegree(attrLONGITUDE);
            } else {
                longitude = 0 - convertToDegree(attrLONGITUDE);
            }
        }

 
        try{
            if(latitude!=null || longitude!=null){
                list = geocoder.getFromLocation(latitude,longitude,10); }
        } catch (IOException e){
            e.printStackTrace();
            Log.e("Test","입출력오류-서버에서 주소 변환시 에러발생");
        }
        if(list!=null){
            if(list.size()==0){
                //onWhere.setText("해당되는 주소 정보가 없음");
                System.out.println("날짜 주소 정보가없음");
            }
            else{
                String cut[] = list.get(0).toString().split(" ");
                for(int i = 0 ; i < cut.length ; i++){
                    System.out.println("cut["+i+"]:"+cut[i]);
                }
                System.out.println("날짜"+cut[1]+ " "+ cut[2]+" "+cut[3]+"\n"+getTagString(ExifInterface.TAG_DATETIME, exif));
        }
        else{
            System.out.println("image날짜 주소 : 데이터 없음\n"+getTagString(ExifInterface.TAG_DATETIME, exif));
        }
        


    }

//호출한 정보 return 함수 

    private String getTagString(String tag, ExifInterface exif) { 

        return (tag + " : " + exif.getAttribute(tag) + "\n"); 
    }

 

-----------------------------------------------------------------------------------------------------------------------------------

20190424 추가

모바일 기기 내의 모든 파일에 대한 날짜 출력

다음 3줄만 있으면 날짜 호출이 가능합니다...

 

File file = new File("파일의 경로 넣기");

SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd / HH:mm:ss");

formatter.format(file.lastModified())

 

 

+ Recent posts