android-Nexus相机-永不返回数据

android-Nexus相机-永不返回数据,第1张

概述在应用程序中,我允许用户将其头像更改为选择的其中之一.然后将图片(一旦裁剪)存储在应用程序的私有上下文中.我的工作取得了很大的成功,但是,在Nexus上,摄像头从不返回数据,因此该方法可以向前发展.它只是坐着等待,直到您必须手动强制关闭该应用程序为止.它可以在其他4.0ICS设备上

在应用程序中,我允许用户将其头像更改为选择的其中之一.然后将图片(一旦裁剪)存储在应用程序的私有上下文中.我的工作取得了很大的成功,但是,在Nexus上,摄像头从不返回数据,因此该方法可以向前发展.它只是坐着等待,直到您必须手动强制关闭该应用程序为止.它可以在其他4.0 ICS设备上运行,但不能在Nexus上运行.Nexus允许用户从图库中进行选择,并且效果很好,只是在拍摄新照片时不行.有一个技巧可以使它正常工作吗???

这是一段代码:

再次请注意,这可以在其他设备上正常使用:

最终的String []项目=新的String [] {“从相机中获取”,“从图库中选择”}};
        ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.select_dialog_item,items);
        AlertDialog.Builder builder =新的AlertDialog.Builder(this);

    builder.setTitle("Select Image");    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {        public voID onClick( DialogInterface dialog, int item ) { //take picture            if (item == 0) {                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);                try {                    intent.putExtra("return-data", true);                    startActivityForResult(intent, PICK_FROM_CAMERA);                } catch (ActivityNotFoundException e) {                    e.printstacktrace();                }            } else { //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();    mImageVIEw = (ImageVIEw) findVIEwByID(R.ID.me_photo);    file file = new file(context.getCacheDir(), "Avatar"+".png");    if (file.exists()) {        //Log.i("CACHE_test", file.getPath());        Bitmap bitmap = BitmapFactory.decodefile(file.getPath());        mImageVIEw.setimageBitmap(bitmap);    }    mImageVIEw.setonClickListener(new VIEw.OnClickListener(){        public voID onClick(VIEw arg0) {            dialog.show();        }    });}@OverrIDeprotected voID onActivityResult(int requestCode, int resultCode, Intent data) {    if (resultCode != RESulT_OK) return;    switch (requestCode) {        case PICK_FROM_CAMERA:            mImageCaptureUri= data.getData();            doCrop();            break;        case PICK_FROM_file:             mImageCaptureUri = data.getData();            doCrop();            break;                  case CROP_FROM_CAMERA:                      Bundle extras = data.getExtras();            if (extras != null) {                               Bitmap photo =(Bitmap) data.getExtras().get("data");                        //extras.getParcelable("data");                mImageVIEw.setimageBitmap(photo);               // fileOutputStream fos = null;                file file = new file(context.getCacheDir(), "Avatar"+".png");                    try {                        file.createNewfile();                        fileOutputStream fos = new fileOutputStream(file);                        photo.compress(Bitmap.CompressFormat.PNG, 95, fos);                    } catch (IOException e) {                        // Todo auto-generated catch block                        Toast.makeText(this, "Sorry, Camera Crashed-Please Report as Crash A.", Toast.LENGTH_LONG).show();                    }             }            break;    }}

解决方法:

这是一个普遍的问题,
某些型号的设备使用不同的额外密钥属性,

所以命令为
位图照片=(位图)data.getExtras().get(“ data”);

可能指向空元素或小的缩略图元素

看看this article

总结

以上是内存溢出为你收集整理的android-Nexus相机-永不返回数据全部内容,希望文章能够帮你解决android-Nexus相机-永不返回数据所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1085934.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存