startActivityForResult()为什么没有跳转?

huhongyuan110 2011-11-29 08:53:57
点击相册图片直接跳转未原来的页面了,没有跳转设计的图片剪切窗口,这是为什么,没有返回值吗?那位GGZZMMDD告诉一下!!!!

public class PPMoresetUI extends Activity implements OnClickListener
{
private RelativeLayout m_phonephoteset;
private RelativeLayout m_network;
private RelativeLayout m_networdtv;
private RelativeLayout m_net;
private Button m_buttonleft;
private Button m_buttonright;
private TextView m_moresettv;
private CheckBox m_check;
private Intent m_Intent;
private String m_moresetFlag;

public static final int NONE = 0;
public static final int PHOTOHRAPH = 1;// 拍照
public static final int PHOTOZOOM = 2; // 缩放
public static final int PHOTORESOULT = 3;// 结果
public static final String IMAGE_UNSPECIFIED = "image/*";

private ImageView m_imageView;

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.moreset);
m_Intent=getIntent();
getIntentData();
init();
showView();

Bitmap wallpaper = this.getWallpager();
m_imageView.setImageBitmap(wallpaper);

}

private void getIntentData()
{
m_moresetFlag=m_Intent.getStringExtra("moresetflag");
}

private void init()
{
//
m_buttonleft = (Button) findViewById(R.id.moresetlefr);
m_buttonright = (Button) findViewById(R.id.moresetright);
m_moresettv = (TextView) findViewById(R.id.morePhoneplusid);

m_phonephoteset = (RelativeLayout) findViewById(R.id.morepersonsetid);
m_network = (RelativeLayout) findViewById(R.id.networksetid);
m_networdtv = (RelativeLayout) findViewById(R.id.textapplictonsetid);
m_net = (RelativeLayout) findViewById(R.id.netsetid);
m_check = (CheckBox) findViewById(R.id.moresetcheckboxID);
m_buttonleft.setOnClickListener(this);
m_buttonright.setOnClickListener(this);
m_phonephoteset.setOnClickListener(this);

m_imageView=(ImageView)findViewById(R.id.morepersonphoneid);

}
private void showView()
{
// TODO Auto-generated method stub
if("phonephoto".equals(m_moresetFlag))
{
m_phonephoteset.setVisibility(View.VISIBLE);
m_moresettv.setText(getString(R.string.Aboutmoresetapp));
// m_buttonleft.setBackgroundResource(R.drawable.pptop_btn);
// m_buttonleft.setWidth(66);
m_buttonleft.setText(getString(R.string.MultiSelectCanBtnID));
m_buttonright.setVisibility(View.VISIBLE);
m_network.setVisibility(View.GONE);
m_networdtv.setVisibility(View.GONE);
m_net.setVisibility(View.GONE);
}
else if("net".equals(m_moresetFlag)){
m_phonephoteset.setVisibility(View.GONE);
m_buttonright.setVisibility(View.GONE);
m_network.setVisibility(View.VISIBLE);
m_networdtv.setVisibility(View.VISIBLE);
m_net.setVisibility(View.VISIBLE);
m_moresettv.setText(getString(R.string.AboutIntenttv));
}
}


// $_FUNCTION_BEGIN ******************************
// 方法名: onClick
// 参 数: View aview
// 返回值:
// 说 明: 处理点击事件
// $_FUNCTION_END ********************************
public void onClick(View aview)
{
switch (aview.getId())
{
case R.id.moresetlefr:
finish();
break;
case R.id.moresetright:
break;
case R.id.morepersonsetid:
dialog();
break;

default:
break;
}
}

// $_FUNCTION_BEGIN ******************************
// 方法名: dialog
// 参 数:
// 返回值:
// 说 明: 取消绑定对话框
// $_FUNCTION_END ********************************
private void dialog()
{
final AlertDialog l_Dialog = new AlertDialog.Builder(this).create();
l_Dialog.show();
l_Dialog.getWindow().setContentView(R.layout.moresetdialog);

Button nativatephoto = (Button) l_Dialog.getWindow().findViewById(
R.id.nativephoto);
Button photo = (Button) l_Dialog.getWindow().findViewById(
R.id.photo);
Button dimiss = (Button) l_Dialog.getWindow().findViewById(
R.id.dimiss);

//相册
nativatephoto.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setDataAndType(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
IMAGE_UNSPECIFIED);

startActivityForResult(intent, PHOTOZOOM);

}
});
//相机
photo.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent
.putExtra(MediaStore.EXTRA_OUTPUT, Uri
.fromFile(new File(getFilesDir(),
"master.png")));
startActivityForResult(intent, PHOTOHRAPH);
}
});
//取消
dimiss.setOnClickListener(new View.OnClickListener()
{

public void onClick(View v)
{
l_Dialog.dismiss();
}
});

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{

if (resultCode == NONE)
return;

// 拍照
if (requestCode == PHOTOHRAPH)
{
// 得到文件路径
File picture = new File(getFilesDir()
+ "/master.png");
startPhotoZoom(Uri.fromFile(picture));
}

if (data == null){
return;
}

// 读取相册缩放图片
if (requestCode == PHOTOZOOM)
{
startPhotoZoom(data.getData());
// 设置文件保存路径这里放在跟目录下
}

// 处理文件
if (requestCode == PHOTORESOULT)
{
Bundle extras = data.getExtras();
if (extras != null)
{
Bitmap photo = extras.getParcelable("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG, 75, stream);// (0 -
// 100)压缩文件

try
{
SaveMyBitmap(photo);
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

super.onActivityResult(requestCode, resultCode, data);
}

//得到图片文件
private Bitmap getWallpager()
{
// 文件路径
File root = getFilesDir();
// MM图片
File wall = new File(root, "master.png");
// MM图片路径
String path = wall.getAbsolutePath();
return BitmapFactory.decodeFile(path);
}

public void startPhotoZoom(Uri uri)
{
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, IMAGE_UNSPECIFIED);
intent.putExtra("crop", "true");
// aspectX aspectY 是宽高的比例
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
// outputX outputY 是裁剪图片宽高
intent.putExtra("outputX", 61);
intent.putExtra("outputY", 61);
intent.putExtra("return-data", true);
startActivityForResult(intent, PHOTORESOULT);

}

public void SaveMyBitmap(Bitmap l_bitmap) throws IOException
{

File l_file = new File(getFilesDir() + "/master.png");

System.out.println(l_file);
l_file.createNewFile();
FileOutputStream l_fileOutputStream = null;
try
{
l_fileOutputStream = new FileOutputStream(l_file);
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
l_bitmap.compress(Bitmap.CompressFormat.PNG, 100, l_fileOutputStream);
try
{
l_fileOutputStream.flush();
} catch (IOException e)
{
e.printStackTrace();
}
try
{
l_fileOutputStream.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
...全文
345 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
安卓机器人 2011-11-30
  • 打赏
  • 举报
回复
1楼是对的,你如果想使用系统自带的裁剪工具,你必须按照一楼的,而且你必须传入你要剪裁图片的URI
老科达 2011-11-29
  • 打赏
  • 举报
回复
first : you can put intent.putExtra("crop", "true"); after Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); it will auto start the crop action;


second: in your code you use the EXTERNAL_CONTENT_URI to fetch data ,
i think the way to get URI has some problem ,check you code ,
EXTERNAL_CONTENT_URI always come with ContentResolver...

80,337

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧