Notice
Recent Posts
Recent Comments
Link
설.현.아빠
갤러리나 사진첩에서 사진을 선택 한 후 해당 사진을 가지고 다른 액티비티로 가고 싶습니다. 본문
public class PhotoActivity extends Activity implements View.OnClickListener{
public static final int REQ_IMAGE_SELECT = 0;
public static final int REQ_CAMERA_SELECT = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photo);
Button camera = (Button)findViewById(R.id.camera);
Button gallary = (Button)findViewById(R.id.gallery);
camera.setOnClickListener(this);
gallary.setOnClickListener(this);
}
public void onClick(View v){
switch(v.getId()){
case R.id.camera :///Call camera
Intent camera_intent = new Intent();
camera_intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camera_intent, REQ_CAMERA_SELECT);
break;
case R.id.gallery ://Call gallery
Intent gallery_intent = new Intent();
gallery_intent.setAction(Intent.ACTION_GET_CONTENT);
gallery_intent.setType("image/*");
startActivityForResult(gallery_intent, REQ_IMAGE_SELECT);
break;
}
}
public static final int REQ_CAMERA_SELECT = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photo);
Button camera = (Button)findViewById(R.id.camera);
Button gallary = (Button)findViewById(R.id.gallery);
camera.setOnClickListener(this);
gallary.setOnClickListener(this);
}
public void onClick(View v){
switch(v.getId()){
case R.id.camera :///Call camera
Intent camera_intent = new Intent();
camera_intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camera_intent, REQ_CAMERA_SELECT);
break;
case R.id.gallery ://Call gallery
Intent gallery_intent = new Intent();
gallery_intent.setAction(Intent.ACTION_GET_CONTENT);
gallery_intent.setType("image/*");
startActivityForResult(gallery_intent, REQ_IMAGE_SELECT);
break;
}
}
위코드로 카메라나 갤러리를 선택하게 한 후
아래의 코드로 onActivityResult 메서드 안에서 촬영된(선택된) 사진을 가지고 원하는 액티비티를 호출했습니다.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQ_IMAGE_SELECT || requestCode == REQ_CAMERA_SELECT){
if(resultCode == Activity.RESULT_OK){
Intent intent = new Intent(PhotoActivity.this, tempActivity.class);
intent.putExtra("PictureURI", data.getData().toString());
startActivity(intent);
}
}
}
}
if(requestCode == REQ_IMAGE_SELECT || requestCode == REQ_CAMERA_SELECT){
if(resultCode == Activity.RESULT_OK){
Intent intent = new Intent(PhotoActivity.this, tempActivity.class);
intent.putExtra("PictureURI", data.getData().toString());
startActivity(intent);
}
}
}
}
폰에 넣고 돌려보니 프로그램이 강제종료 되네요
onActivityResult 에서는 다른 액티비티를 호출 할 수 없나요?
안된다면 다른 액티비티를 호출하는 방법은 없나요?
부탁드립니다.
'안드로이드 > Image' 카테고리의 다른 글
3D 회전효과 주기. (0) | 2011.07.12 |
---|---|
Uri & Bitmap & byte[].....캐스팅 문제 (1) | 2011.06.10 |
ImageView를 사용하여 ListView에 이미지 로딩시 느리지 않도록 해주는 오픈소스. (0) | 2011.04.26 |
안드로이드 외부 이미지 사용하기(ListView,WebView) (0) | 2011.02.11 |
[팁] 원격지 서버에서 Image 파일을 다운받아 ImageView에 로드하기. (0) | 2011.02.11 |
Comments