本文介绍了画廊已经停止,而在奇巧Nexus7裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我从库获取图像,之后随之而来的形象和完美的工作在所有设备上。但它在的Nexus 7奇巧运行,因为我已经检查版本版本用画廊停止错误,而给我的错误。我已经实现了code和所有其他neccessary许可清单文件仍然没有得到回应。因此,任何人可以解决此问题?

这是我的code:

 最终的String []项目=新的String [] {从相机拿,
            从库中选择};
    ArrayAdapter<字符串>适配器=新的ArrayAdapter<字符串>(这一点,
            android.R.layout.select_dialog_item,项目);
    AlertDialog.Builder建设者=新AlertDialog.Builder(本);

    builder.setTitle(选择图片);
    builder.setAdapter(适配器,新DialogInterface.OnClickListener(){
        公共无效的onClick(DialogInterface对话,诠释项){//挑选
                                                                // 相机
            如果(项目== 0){
                意向意图=新的意图(MediaStore.ACTION_IM​​AGE_CAPTURE);

                mImageCaptureUri = Uri.fromFile(新文件(环境
                        .getExternalStorageDirectory(),tmp_avatar_
                        +将String.valueOf(System.currentTimeMillis的())
                        +.JPG));

                intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                        mImageCaptureUri);

                尝试 {
                    intent.putExtra(回归数据,真正的);

                    startActivityForResult(意向,PICK_FROM_CAMERA);
                }赶上(ActivityNotFoundException E){
                    e.printStackTrace();
                }
            }其他{//挑选文件

                意向意图;

                如果(Build.VERSION.SDK_INT所述19){
                    意图=新的意图();
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    intent.setType(* / *);
                    startActivityForResult(Intent.createChooser(意向,
                            完整的行动使用),PICK_FROM_FILE);
                } 其他 {
                    意图=新的意图(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.setType(* / *);
                    startActivityForResult(Intent.createChooser(意向,

                    完整的行动使用),PICK_FROM_FILE);
                }
                / *
                 *意向意图=新的意图();
                 *
                 * intent.setType(图像/ *);
                 * intent.setAction(Intent.ACTION_GET_CONTENT);
                 *
                 * startActivityForResult(Intent.createChooser(意向,
                 *完成操作使用),PICK_FROM_FILE);
                 * /
            }
        }
    });

    最后AlertDialog对话框= builder.create();

    btnTakephoto.setOnClickListener(新View.OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            dialog.show();
        }
    });
}

@覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
    如果(结果code!= RESULT_OK)
        返回;

    开关(要求code){
    案例PICK_FROM_CAMERA:
        doCrop();

        打破;

    案例PICK_FROM_FILE:

        如果(Build.VERSION.SDK_INT所述19){
            mImageCaptureUri = data.getData();

        } 其他 {
            mImageCaptureUri = data.getData();
            ParcelFileDescriptor parcelFileDescriptor;
            尝试 {
                parcelFileDescriptor = getContentResolver()
                        .openFileDescriptor(mImageCaptureUri,R);
                的FileDescriptor文件描述符= parcelFileDescriptor
                        .getFileDescriptor();
                MYBITMAP = BitmapFactory
                        .DE codeFileDescriptor(文件描述符);
                parcelFileDescriptor.close();

            }赶上(FileNotFoundException异常E){
                e.printStackTrace();
            }赶上(IOException异常E){
                // TODO自动生成的catch块
                e.printStackTrace();
            }
        }

        doCrop();

        打破;

    案例CROP_FROM_CAMERA:
        捆绑额外= data.getExtras();

        如果(临时演员!= NULL){
            MYBITMAP = extras.getParcelable(数据);

        }

        文件F =新的文件(mImageCaptureUri.getPath());

        如果(f.exists()){
            f.delete();
        }

        ByteArrayOutputStream流=新ByteArrayOutputStream();
        myBitmap.com preSS(Bitmap.Com pressFormat.PNG,100,流);

        的字节数组= stream.toByteArray();

        意图N =新意图();
        n.setClass(getApplicationContext(),EffectsActivity.class);
        n.putExtra(图片报,字节);
        startActivity(N);
        打破;

    }
}

私人无效doCrop(){
    最后的ArrayList< CropOption> cropOptions =新的ArrayList< CropOption>();

    意向意图=新的意图(com.android.camera.action.CROP);
    intent.setType(图像/ *);

    名单< ResolveInfo>表= getPackageManager()。queryIntentActivities(
            意图,0);

    INT大小=则为list.size();

    如果(大小== 0){
        Toast.makeText(这一点,找不到图像裁剪的应用程序,
                Toast.LENGTH_SHORT).show();

        返回;
    } 其他 {
        如果(mImageCaptureUri!= NULL){
            intent.setData(mImageCaptureUri);
        }

        intent.putExtra(outputX,350);
        intent.putExtra(outputY,350);
        intent.putExtra(aspectX,1);
        intent.putExtra(aspectY,1);
        intent.putExtra(规模化,真正的);
        intent.putExtra(回归数据,真正的);

        如果(尺寸== 1){
            意图I =新的意向(意向);
            ResolveInfo解析度= list.get(0);

            i.setComponent(新的组件名(res.activityInfo.packageName,
                    res.activityInfo.name));

            startActivityForResult(ⅰ,CROP_FROM_CAMERA);
        } 其他 {
            对于(ResolveInfo RES:名单){
                最后CropOption合作=新CropOption();

                co.title = getPackageManager()。getApplicationLabel(
                        res.activityInfo.applicationInfo);
                co.icon = getPackageManager()。getApplicationIcon(
                        res.activityInfo.applicationInfo);
                co.appIntent =新的意图(意图);

                co.appIntent
                        .setComponent(新的组件名(
                                res.activityInfo.packageName,
                                res.activityInfo.name));

                cropOptions.add(共);
            }

            CropOptionAdapter适配器=新CropOptionAdapter(
                    getApplicationContext(),cropOptions);

            AlertDialog.Builder建设者=新AlertDialog.Builder(本);
            builder.setTitle(选择作物应用程序);
            builder.setAdapter(适配器,
                    新DialogInterface.OnClickListener(){
                        公共无效的onClick(DialogInterface对话,诠释项){
                            startActivityForResult(
                                    cropOptions.get(项目).appIntent,
                                    CROP_FROM_CAMERA);
                        }
                    });

            builder.setOnCancelListener(新DialogInterface.OnCancelListener(){
                @覆盖
                公共无效OnCancel的(DialogInterface对话){

                    如果(mImageCaptureUri!= NULL){
                        getContentResolver()。删除(mImageCaptureUri,空,
                                空值);
                        mImageCaptureUri = NULL;
                    }
                }
            });

            AlertDialog警报= builder.create();

            alert.show();
        }
    }
 

CropAction:

 公共类CropOption {
  公共CharSequence的称号;
  公众可绘制图标;
  公众意向appIntent;
 }
 

CropOptionAdapter.java

 公共类CropOptionAdapter扩展ArrayAdapter< CropOption> {
私人的ArrayList< CropOption> mOptions;
私人LayoutInflater mInflater;

公共CropOptionAdapter(上下文的背景下,ArrayList的< CropOption>选项){
    超(背景下,R.layout.crop_selector,期权);

    mOptions =选项;

    mInflater = LayoutInflater.from(上下文);
}

@覆盖
公共查看getView(INT位置,查看convertView,ViewGroup中组){
    如果(convertView == NULL)
        convertView = mInflater.inflate(R.layout.crop_selector,NULL);

    CropOption项目= mOptions.get(位置);

    如果(项目!= NULL){
        ((ImageView的)convertView.findViewById(R.id.iv_icon))
                .setImageDrawable(item.icon);
        ((TextView中)convertView.findViewById(R.id.tv_name))
                .setText(item.title);

        返回convertView;
    }

    返回null;
}
    }
 

解决方案

我已经解决了我的问题。

我有什么做的,

我刚刚从

更改此

 意图=新的意图(Intent.ACTION_OPEN_DOCUMENT);
 intent.addCategory(Intent.CATEGORY_OPENABLE);
 intent.setType(* / *);
 startActivityForResult(Intent.createChooser(原意,用完整的行动),PICK_FROM_FILE);
 

 意图=新的意图(Intent.ACTION_PICK);
 intent.setType(* / *);
 intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                            mImageCaptureUri);
 startActivityForResult(Intent.createChooser(原意,用完整的行动),PICK_FROM_FILE);
 

工作般的魅力。

谢谢大家。

Problem:I am fetching image from gallery and after that cropped that image and its working perfect in all device. But it is giving me error while running in Nexus 7 kitkat since i have checked build version for it with "Gallery Stopped" error. I have implemented code and all other neccessary permission in manifest file still not getting response. So can anybody resolve this?

Here is my Code:

 final String[] items = new String[] { "Take from camera",
            "Select from gallery" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.select_dialog_item, items);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle("Select Image");
    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) { // pick from
                                                                // camera
            if (item == 0) {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

                mImageCaptureUri = Uri.fromFile(new File(Environment
                        .getExternalStorageDirectory(), "tmp_avatar_"
                        + String.valueOf(System.currentTimeMillis())
                        + ".jpg"));

                intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                        mImageCaptureUri);

                try {
                    intent.putExtra("return-data", true);

                    startActivityForResult(intent, PICK_FROM_CAMERA);
                } catch (ActivityNotFoundException e) {
                    e.printStackTrace();
                }
            } else { // pick from file

                Intent intent;

                if (Build.VERSION.SDK_INT < 19) {
                    intent = new Intent();
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    intent.setType("*/*");
                    startActivityForResult(Intent.createChooser(intent,
                            "Complete action using"), PICK_FROM_FILE);
                } else {
                    intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.setType("*/*");
                    startActivityForResult(Intent.createChooser(intent,

                    "Complete action using"), PICK_FROM_FILE);
                }
                /*
                 * Intent intent = new Intent();
                 *
                 * intent.setType("image/*");
                 * intent.setAction(Intent.ACTION_GET_CONTENT);
                 *
                 * startActivityForResult(Intent.createChooser(intent,
                 * "Complete action using"), PICK_FROM_FILE);
                 */
            }
        }
    });

    final AlertDialog dialog = builder.create();

    btnTakephoto.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.show();
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK)
        return;

    switch (requestCode) {
    case PICK_FROM_CAMERA:
        doCrop();

        break;

    case PICK_FROM_FILE:

        if (Build.VERSION.SDK_INT < 19) {
            mImageCaptureUri = data.getData();

        } else {
            mImageCaptureUri = data.getData();
            ParcelFileDescriptor parcelFileDescriptor;
            try {
                parcelFileDescriptor = getContentResolver()
                        .openFileDescriptor(mImageCaptureUri, "r");
                FileDescriptor fileDescriptor = parcelFileDescriptor
                        .getFileDescriptor();
                myBitmap = BitmapFactory
                        .decodeFileDescriptor(fileDescriptor);
                parcelFileDescriptor.close();

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

        doCrop();

        break;

    case CROP_FROM_CAMERA:
        Bundle extras = data.getExtras();

        if (extras != null) {
            myBitmap = extras.getParcelable("data");

        }

        File f = new File(mImageCaptureUri.getPath());

        if (f.exists()) {
            f.delete();
        }

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        myBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);

        byteArray = stream.toByteArray();

        Intent n = new Intent();
        n.setClass(getApplicationContext(), EffectsActivity.class);
        n.putExtra("picture", byteArray);
        startActivity(n);
        break;

    }
}

private void doCrop() {
    final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>();

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setType("image/*");

    List<ResolveInfo> list = getPackageManager().queryIntentActivities(
            intent, 0);

    int size = list.size();

    if (size == 0) {
        Toast.makeText(this, "Can not find image crop app",
                Toast.LENGTH_SHORT).show();

        return;
    } else {
        if (mImageCaptureUri != null) {
            intent.setData(mImageCaptureUri);
        }

        intent.putExtra("outputX", 350);
        intent.putExtra("outputY", 350);
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);

        if (size == 1) {
            Intent i = new Intent(intent);
            ResolveInfo res = list.get(0);

            i.setComponent(new ComponentName(res.activityInfo.packageName,
                    res.activityInfo.name));

            startActivityForResult(i, CROP_FROM_CAMERA);
        } else {
            for (ResolveInfo res : list) {
                final CropOption co = new CropOption();

                co.title = getPackageManager().getApplicationLabel(
                        res.activityInfo.applicationInfo);
                co.icon = getPackageManager().getApplicationIcon(
                        res.activityInfo.applicationInfo);
                co.appIntent = new Intent(intent);

                co.appIntent
                        .setComponent(new ComponentName(
                                res.activityInfo.packageName,
                                res.activityInfo.name));

                cropOptions.add(co);
            }

            CropOptionAdapter adapter = new CropOptionAdapter(
                    getApplicationContext(), cropOptions);

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Choose Crop App");
            builder.setAdapter(adapter,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int item) {
                            startActivityForResult(
                                    cropOptions.get(item).appIntent,
                                    CROP_FROM_CAMERA);
                        }
                    });

            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {

                    if (mImageCaptureUri != null) {
                        getContentResolver().delete(mImageCaptureUri, null,
                                null);
                        mImageCaptureUri = null;
                    }
                }
            });

            AlertDialog alert = builder.create();

            alert.show();
        }
    }

CropAction:

 public class CropOption {
  public CharSequence title;
  public Drawable icon;
  public Intent appIntent;
 }

CropOptionAdapter.java

public class CropOptionAdapter extends ArrayAdapter<CropOption> {
private ArrayList<CropOption> mOptions;
private LayoutInflater mInflater;

public CropOptionAdapter(Context context, ArrayList<CropOption> options) {
    super(context, R.layout.crop_selector, options);

    mOptions = options;

    mInflater = LayoutInflater.from(context);
}

@Override
public View getView(int position, View convertView, ViewGroup group) {
    if (convertView == null)
        convertView = mInflater.inflate(R.layout.crop_selector, null);

    CropOption item = mOptions.get(position);

    if (item != null) {
        ((ImageView) convertView.findViewById(R.id.iv_icon))
                .setImageDrawable(item.icon);
        ((TextView) convertView.findViewById(R.id.tv_name))
                .setText(item.title);

        return convertView;
    }

    return null;
}
    }
解决方案

I have resolved my problem.

What i have do,

I have just change this from

 intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
 intent.addCategory(Intent.CATEGORY_OPENABLE);
 intent.setType("*/*");
 startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);

to

 intent = new Intent(Intent.ACTION_PICK);
 intent.setType("*/*");
 intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                            mImageCaptureUri);
 startActivityForResult(Intent.createChooser(intent,"Complete action using"), PICK_FROM_FILE);

Working like charm.

Thanks Everyone.

这篇关于画廊已经停止,而在奇巧Nexus7裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 08:47