안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요~
제가 어플하나를 개발하고 있는데
기능중에
1. 버튼을 누르면 기본 시스템 갤러리로 연결
2. 갤러리에서 오래 누르고 있으면 뜨는 다이얼로그 중 share를 누르면 제 어플로 이미지를 불러오는 기능
요거 두개가 필요한데요 .. 1번은
public void onClick(View view){
Uri uri = Uri.parse("content://media/internal/images/media");
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
요렇게 해서 연결해 줬구요
문제는 2번인데... 갤러리를 건드리지 않고 제 어플에서 핸들링 할 수 없을까요?
사실 갤러리안에 다음 소스만 건드려 주면 끝나는 일인데, 그렇게 하려면 갤러리를 제 프로젝트에 추가시켜야 할 것 같아서요 ㅠㅠ
고수님들의 조언 부탁드립니다.
String content = currentTodo.get("content"); Intent msg = new Intent(Intent.ACTION_SEND); msg.addCategory(Intent.CATEGORY_DEFAULT); msg.putExtra(Intent.EXTRA_SUBJECT, R.string.share_subject); msg.putExtra(Intent.EXTRA_TEXT, content); msg.putExtra(Intent.EXTRA_TITLE, ""); msg.setType("text/plain"); startActivity(Intent.createChooser(msg, getString(R.string.share_title)));
2010.04.12 10:38:56
필요하신 기능이 갤러리의 사진을 나의 어플로 가져오는 건가요?
그렇다면 말씀하신대로 갤러리의 "공유" 기능을 사용하지 않아도 됩니다.
버튼 클릭시 아래와 같이 갤러리로 가도록 하구요
Intent intent = new Intent();
intent.setAction( Intent.ACTION_GET_CONTENT );
intent.setType( "image/*" );
startActivityForResult( intent, REQ_IMAGE_SELECT );
onActivityResult() 메소드를 오버라이딩하여 갤러리에서 사진 선택시 아래와 같이 선택한 사진에 대한 Bitmap 객체를 받을 수 있습니다.
try {
Uri selPhotoUri = data.getData();
Bitmap selPhoto = Images.Media.getBitmap( getContentResolver(), selPhotoUri );
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}