現在、ギャラリー/カメラから画像を取得して画像ビューに設定するタスクに取り組んでおり、タブグループ アクティビティを使用しています。この onActivityResult は呼び出していません。私のコードを確認してください。
public class Create_Event extends BaseActivity{
ImageView prof;
String imagepath;
Button next;
private static int RESULT_LOAD_IMAGE = 1;
@SuppressLint("HandlerLeak")
public void onCreate(Bundle savedInstanceState) {
setLayoutId(this, R.layout.createevent);
super.onCreate(savedInstanceState);
mHandler = new Handler()
{
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case Constants.MSG_CHOOSE_PHOTO: {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// startActivityForResult(i,Constants.MSG_CHOOSE_PHOTO);
System.out.println("fghdfgldgdjlgjdjgldfjgdfgdfjgl;f");
startActivityForResult(i,Constants.MSG_CHOOSE_PHOTO);
}
break;
}
}
};
initview();
}
public void initview() {
prof=(ImageView)findViewById(R.id.eventimg);
prof.setOnClickListener(this);
next =(Button)findViewById(R.id.button1);
next.setOnClickListener(this);
if(Constants.getPicture_path().toString().length()>0)
{
prof.setImageBitmap(BitmapFactory.decodeFile(Constants.getPicture_path().toString()));
}
registerForContextMenu(prof);
}
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Choose Image from");
menu.add(0, v.getId(), 0, "Gallery");
menu.add(0, v.getId(), 0, "camera");
}
@Override
public boolean onContextItemSelected(MenuItem item)
{
if(item.getTitle()=="Gallery")
{
function1(item.getItemId());
}
else if(item.getTitle()=="camera")
{
function2(item.getItemId());
}
else
{
return false;
}
return true;
}
private void function1(int itemId)
{
mHandler.sendEmptyMessage(Constants.MSG_CHOOSE_PHOTO);
}
private void function2(int itemId)
{
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT, "/mnt/sdcard/profile_image.jpg");
imagepath="/mnt/sdcard/montacts_profile_image.jpg";
startActivityForResult(intent, 1);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee;f");
if (requestCode == Constants.MSG_CHOOSE_PHOTO && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
imagepath=picturePath;
Constants.setPicture_path(picturePath);
// Bitmap b = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)
//profileImage.setImageBitmap(Bitmap.createScaledBitmap(b, 120, 120, false));
prof.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
else if(requestCode == 1){
if(data != null)
{
Bitmap photo = (Bitmap) data.getExtras().get("data");
photo = photo.createScaledBitmap(photo, 80, 80, false);
prof.setImageBitmap(photo);
}
else
{
}
}
}
public void onClick(View view) {
int viewId = view.getId();
switch (viewId) {
case R.id.eventimg:
{
//Intent i=new Intent(this,New_imgsel.class);
//startActivity(i);
}
break;
case R.id.button1:
{
}
break;
}
}
}