实现二维码扫描后跳转

实现二维码扫描后跳转

public void handleDecode(Result result, Bitmap barcode) {
    ////压缩图片保证不栈溢出,这两句是关键!
    Bitmap tempCode = barcode;   
    barcode =scaleDownBitmap(tempCode, 64, getApplicationContext());

        inactivityTimer.onActivity();
        playBeepSoundAndVibrate();
        String resultString = result.getText();
        if (resultString.equals("") || resultString.length() < 11) {
            Toast.makeText(LoginActivityCapture.this, "扫描失败请重试",
                    Toast.LENGTH_SHORT).show();
            Intent resultIntent = new Intent();
            Bundle bundle = new Bundle();
            bundle.putString("result", "");
            this.setResult(RESULT_OK, resultIntent);
            LoginActivityCapture.this.finish();
        } else {
            MixLog.i(Macro.DEBUG_TAG, "*******scan code result:" + resultString);
            boolean conUUid = resultString.contains("uuid=");
            Intent resultIntent = new Intent();
            Bundle bundle = new Bundle();
            if (conUUid) {
                String resultTmp[] = resultString.split("uuid=");
                if (resultTmp.length > 1) {
                    resultIntent.setAction(Macro.broadcast_scan_qc);
                    bundle.putString("result", resultTmp[1]);
                    resultIntent.putExtras(bundle);
                    this.sendBroadcast(resultIntent);
                    MixLog.i(Macro.DEBUG_TAG, "*******scan code result:"
                            + resultTmp[1]);
                    LoginActivityCapture.this.finish();
                } else {// uuid为空
                    Toast.makeText(LoginActivityCapture.this,
                            "二维码无效请退出电视客户端重试", Toast.LENGTH_SHORT).show();
                    LoginActivityCapture.this.finish();
                }
            } else {
                bundle.putString("result", resultString);
                bundle.putParcelable("bitmap", barcode);
                resultIntent.putExtras(bundle);
                this.setResult(RESULT_OK, resultIntent);
                String mobileNum = resultString.substring(
                        resultString.length() - 11, resultString.length());
                MixLog.i(Macro.DEBUG_TAG, "*******scan code result:" + mobileNum);
                // skip to san result activity page
                searchProfileByMobileNum(mobileNum);


                // finish();
            }
        }
    }

/**
     * 压缩扫描后的图片
     * @param photo
     * @param newHeight
     * @param context
     * @return
     */
   public static Bitmap scaleDownBitmap(Bitmap photo, int newHeight, Context context) {


    final float densityMultiplier = context.getResources().getDisplayMetrics().density;        


    int h= (int) (newHeight*densityMultiplier);
    int w= (int) (h * photo.getWidth()/((double) photo.getHeight()));


    photo=Bitmap.createScaledBitmap(photo, w, h, true);


    return photo;
    }

你可能感兴趣的:(Android--第三方框架,Android--小知识点)