Android_照相机Camera_调用系统照相机返回data为空


 



     protected void onSaveInstanceState(Bundle outState) {  
        // TODO Auto-generated method stub  
        super.onSaveInstanceState(outState);  
        outState.putInt("save", 11);  
        Log.i(TAG, "onSaveInstanceState, data is "+outState.getInt("save"));  
    }  
    @Override  
    protected void onRestoreInstanceState(Bundle savedInstanceState) {  
        // TODO Auto-generated method stub  
        super.onRestoreInstanceState(savedInstanceState);  
        Log.i(TAG, "onrestore, data is "+savedInstanceState.getInt("save"));  
    }   



public class MerchantCertifBusinessLicenseActivity extends BaseActivity {

    private static final int REQUEST_PHOTO_GALLERY = 1;
    private static final int REQUEST_PHOTO_TAKE = 2;

    private Bitmap mBusinessLicenseBtp;
    private ImageView mBusinessLicenseImageView;
    <del><span style="color:#ff0000;">private static String mBtpFileStr;</span></del>
    private File mBtpFile;

    private Toast mToast;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_merchant_certif_business_license);
        mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
        mBusinessLicenseImageView = (ImageView) findViewById(R.id.merchant_certif_business_license_activity_take);

        findViewById(R.id.merchant_certif_business_license_activity_back)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                });

        findViewById(R.id.merchant_certif_business_license_activity_take)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        initPhotoSelectorPopwindow(v);
                    }
                });
    }

    private void initPhotoSelectorPopwindow(View parent) {

        View view = LayoutInflater.from(this).inflate(
                R.layout.activity_merchant_cerfit_ic_card_take_photo, null);

        ((TextView) (view.findViewById(R.id.merchant_certif_id_card_activity_take_title)))
                .setText("拍摄营业执照照片");

        Display display = getWindowManager().getDefaultDisplay();
        int desWidth = (int) ((display.getWidth()) * 0.9);

        final PopupWindow popupWindow = new PopupWindow(view, desWidth
                , ViewGroup.LayoutParams.WRAP_CONTENT);

        popupWindow.setAnimationStyle(R.style.popwin_anim_style);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setOutsideTouchable(true);
        popupWindow.setFocusable(true);
        popupWindow.showAtLocation(
                parent, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);

        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1.0f;
                getWindow().setAttributes(lp);
            }
        });

        view.findViewById(R.id.merchant_certif_id_card_activity_take_cancel)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        popupWindow.dismiss();
                    }
                });

        view.findViewById(R.id.merchant_certif_id_card_activity_take_gallery)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(Intent.ACTION_PICK);
                        intent.setType("image/*");
                        startActivityForResult(intent, REQUEST_PHOTO_GALLERY);
                        popupWindow.dismiss();
                    }
                });

        view.findViewById(R.id.merchant_certif_id_card_activity_take_photo)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                            Calendar currentDate = Calendar.getInstance();
                            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(currentDate.getTime());
                            String pathStr = Environment.getExternalStorageDirectory() + "/com.genzzhang.shupian";
                            File pathFile = new File(pathStr);
                            if(!pathFile.exists()) pathFile.mkdirs();
                            mBtpFile = new File(pathFile, "/IMG_" + timeStamp + ".jpg");
                            mBtpFileStr = mBtpFile.getAbsolutePath();
                            if(!mBtpFile.exists())
                                try {
                                    mBtpFile.createNewFile();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mBtpFile));
                            startActivityForResult(intent, REQUEST_PHOTO_TAKE);
                            popupWindow.dismiss();
                        } else {
                            mToast.setText("未找到存储卡");
                            mToast.show();
                            return;
                        }
                    }
                });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) return;
        switch (requestCode) {
            case REQUEST_PHOTO_GALLERY:
                // mFoodServiceBtp = (Bitmap)data.getExtras().get("data");
                if(data != null) {
                    try {
                        mBusinessLicenseBtp = BitmapFactory.decodeStream(
                                getContentResolver().openInputStream(data.getData())
                        );
                        mBusinessLicenseImageView.setImageBitmap(mBusinessLicenseBtp);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                }
                break;
            case REQUEST_PHOTO_TAKE:
                <del>File tempFile = new File(mBtpFileStr);</del>
                try {
                    mBusinessLicenseBtp = BitmapFactory.decodeStream(
                            getContentResolver().openInputStream(Uri.fromFile(tempFile))
                    );
                    mBusinessLicenseImageView.setImageBitmap(mBusinessLicenseBtp);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                break;
            default:
                break;
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mBusinessLicenseBtp != null && !mBusinessLicenseBtp.isRecycled())
            mBusinessLicenseBtp.recycle();
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值