setDateAndType setDate setType

遇到个这样的问题,就是吃了没马上看源码的亏,想当然的以为setDateAndType拆开来应该也能用。

拍照和从相册选择图片剪切时由于拍照的时候有路径传回,就需要判断。

懒人的懒办法就出来了,拆setDateAndType,自己还挺开心的。

接着这一块的功能就不能用了。找半天......................................................


public static Intent getCropImageIntent(Uri photoUri) {

Intent intent = null;
if (photoUri !=null) {
intent = new Intent("com.android.camera.action.CROP");
intent.setData(photoUri);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
}else {
intent = new Intent(Intent.ACTION_GET_CONTENT, null);

}
intent.setType("image/*");
// crop=true 设置在开启的Intent中显示的VIEW可裁剪
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 80);
intent.putExtra("outputY", 80);
intent.putExtra("return-data", true)
return intent;
}


*************************************************************************************************************************************

逐渐定位到问题所在,然后就骂街了。。

这几个set方法在源码当中是这样的:

public Intent setData(Uri data) {
    mData = data;
    mType = null;
    return this;
}

public Intent setType(String type) {
    mData = null;
    mType = type;
    return this;
}
public Intent setDataAndType(Uri data, String type) {
        mData = data;
        mType = type;
        return this;
    }


public static Intent getCropImageIntent(Uri photoUri) {


Intent intent = null;
if (photoUri !=null) {
intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(photoUri, "image/*");
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
}else {
 intent = new Intent(Intent.ACTION_GET_CONTENT, null);
 intent.setType("image/*");
}

// crop=true 设置在开启的Intent中显示的VIEW可裁剪
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 80);
intent.putExtra("outputY", 80);
intent.putExtra("return-data", true);
return intent;

}

留个记忆,重新做人


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值