我创建的应用程序将使用zxing扫描qrcode。 下面是CameraPreview的代码,它扫描数据并显示弹出窗口 但我想将数据发送回活动,以便我可以在活动中使用相同的内容。
CameraPreview.java
private Camera.PreviewCallback mPreviewCallback = new PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
// TODO Auto-generated method stub
if (mDialog.isShowing())
return;
LuminanceSource source = new PlanarYUVLuminanceSource(data, mWidth, mHeight, mLeft, mTop, mAreaWidth, mAreaHeight, false);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(
source));
Result result;
try {
result = mMultiFormatReader.decode(bitmap, null);
if (result != null) {
mDialog.setTitle("Result");
mDialog.setMessage(result.getText());
mDialog.show();
Scanbarcode scanbarcode= new Scanbarcode();
scanbarcode.afterscan(result.getText());
}
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
我想将扫描数据传递给afterscan,以便我可以在代码中使用但是应用程序在android.content.Contextwrapper.getPackageName上抛出NullPointerException
Scanbarcode.java
public void afterscan(string code)
{
scancode = (TextView)findViewById(R.id.code);
scancode.setText(code);
}