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

앱에서 동영상을 복사하고 싶습니다.

0 추천
이미지 같은 경우는요

    Intent clsIntent = new Intent(Intent.ACTION_PICK);               
    clsIntent.setType(android.provider.MediaStore.Images.Media.CONTENT_TYPE);
    clsIntent.setData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult( clsIntent, 101 );

이미지 선택 후

protected void onActivityResult( int requestCode, int resultCode, Intent data )

이 함수 안에서

    bkBitmap = Images.Media.getBitmap( getContentResolver(), data.getData() );
    FileOutputStream fileoutst=new FileOutputStream(path+"/ad1.jpg");
    bkBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileoutst);
    fileoutst.flush();
    fileoutst.close();

이런 식으로  원하는 위치에 저장을 잘 하였습니다.

 

근데 동영상은 어떻게 해야 할지 모르겠스니다.ㅠㅠ

    Intent clsIntent = new Intent(Intent.ACTION_PICK);               
    clsIntent.setType(android.provider.MediaStore.Video.Media.CONTENT_TYPE);
    clsIntent.setData(android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult( clsIntent, 111 );

동영상을 위의 소스를 이용하여 선택할수 있게 했습니다.

그 다음

protected void onActivityResult( int requestCode, int resultCode, Intent data )

이곳에서 동영상을 다른곳으로 저장하고 싶은데 어떻게 해야 할까요??
ppst (500 포인트) 님이 2016년 2월 26일 질문

1개의 답변

0 추천
 
채택된 답변

굳이 Bitmap 압축을 시켜야 하나요?? 이미지파일, 동영상 파일을 그대로 복사하는것이라면 경로만 알고 있다면 간단합니다.

 

onActivityResult에서 파일 경로만 알수 있다면 아래와 같이 해보세요.

FileInputStream fis = new FileInputStream("복사할 소스 파일 full path");
FileOutputStream fos = new FileOutputStream("복사할 목적지 경로 fullpath");
int nReadCnt = 0;
byte[] buffer = new byte[4096];
while((nReadCnt = fis.read(buffer, 0, buffer.length))>0){
   fos.write(buffer, 0, nReadCnt);
   fos.flush();
}
fis.close();
fos.close();

 

아마 ACTION_PICK으로 미디어파일을 선택하였을경우 onActivityResult의 Intent data 파라미터안에 소스파일 정보가 URI로 담겨 있을 것입니다. 

URI를 통해 파일 경로를 얻으려면 아래 링크를 참조하세요.

http://stackoverflow.com/questions/3401579/get-filename-and-path-from-uri-from-mediastore

 

 

Development Guy (70,570 포인트) 님이 2016년 2월 29일 답변
ppst님이 2016년 6월 9일 채택됨
...