마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 getExternalStorageDirectory 질문입니다.

0 추천
usb 경로를 가져오는 개발도중에 드는 의문이 생겼는데

getExternalStorageDirectory 라는단어가 외부저장소를 가져오는것인데 내부저장소를 가져오는이유가 무엇일까요??

getExternalStorageDirectory.getabsolutepath가 내부저장소를 가져온다면  진짜로 안드로이드가 usb를 인식했을때 외부저장소인 usb경로를 가져오려면  어떻게해야 가져올수있을까요??
dsafdsf (300 포인트) 님이 2016년 8월 17일 질문

1개의 답변

0 추천
 
채택된 답변
초기 안드로이드 제품들을 보면 외장메모리가 없었습니다.

 따라서, 외장메모리가 없으면, 저장용량이 많이 필요한 카메라앱 같은 경우, 동작을 하지 않았습니다.

 시간이 지나고 소토리지가 대용량화 되면서 외장메모리가 스마트폰에 내장되었다고 생각하시면 됩니다.

 물리적으로 내장되었다고 생각하시면 될 것 같습니다.

 removable storage의 경우 http://devbible.tistory.com/277 참조해서 구현하시면 되겠습니다.
안_드루이드 (14,510 포인트) 님이 2016년 8월 17일 답변
dsafdsf님이 2016년 8월 17일 채택됨
답변 감사합니다. 덕분에 첫번째 의문점이 해결이되었습니다.

그런데 해당url을 참고하여 usb 경로값을받아오면 /mnt/media_rw/UsbDriveA
를 반환값으로 받는데 실제경로는 /storage/UsbDriveA입니다.
다른방법은 없을까요??
String strSDCardPath = System.getenv("SECONDARY_STORAGE");

    if ((strSDCardPath == null) || (strSDCardPath.length() == 0)) {
        strSDCardPath = System.getenv("EXTERNAL_SDCARD_STORAGE");
    }

    //If may get a full path that is not the right one, even if we don't have the SD Card there.
    //We just need the "/mnt/extSdCard/" i.e and check if it's writable
    if(strSDCardPath != null) {
        if (strSDCardPath.contains(":")) {
            strSDCardPath = strSDCardPath.substring(0, strSDCardPath.indexOf(":"));
        }
        File externalFilePath = new File(strSDCardPath);

        if (externalFilePath.exists() && externalFilePath.canWrite()){
            //do what you need here
        }
    }

 이렇게 한번 해보세요..
답변감사합니다 답변대로 실행한결과

        strSDCardPath = System.getenv("SECONDARY_STORAGE");

        if ((strSDCardPath == null) || (strSDCardPath.length() == 0)) {
            strSDCardPath = System.getenv("EXTERNAL_SDCARD_STORAGE");
        }

        //If may get a full path that is not the right one, even if we don't have the SD Card there.
        //We just need the "/mnt/extSdCard/" i.e and check if it's writable
        if(strSDCardPath != null) {
            if (strSDCardPath.contains(":")) {
                strSDCardPath = strSDCardPath.substring(0, strSDCardPath.indexOf(":"));
            }
            File externalFilePath = new File(strSDCardPath);

            if (externalFilePath.exists() && externalFilePath.canWrite()){
                //do what you need here
            }
        }

        Log.i("test","strSDCardPath : " + strSDCardPath);

로그값결과 strSDCardPath : /storage/extSdCard 해당경로에는 아무런파일이없습니다.

위와같이   /storage/UsbDriveA 경로값을 받질못합니다.
안되면 아까전 방법에서 실제 파일을 생성해 보세요. 알다시피 리눅스에서는 디렉토리 자체도 링크가 되기 때문에 디렉토리 명이 달라도 물리적으로는 같은 디레토리 일수도 있습니다.
...