我想将条形码扫描结果存储在新活动中请帮帮我。在这种情况下SQLight数据库使用?
这是我的代码:
public class Barcode_Activity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.barcode_activity);
mScannerView = new ZXingScannerView(this);
setContentView(mScannerView);
}
@Override
public void handleResult(Result result) {
Log.v("TAG", result.getText());
Log.v("TAG", result.getBarcodeFormat().toString());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Scan Result");
builder.setMessage(result.getText());
AlertDialog alert1 = builder.create();
alert1.show();
mScannerView.resumeCameraPreview(this);
}
@Override
protected void onResume() {
mScannerView.setResultHandler(this);
mScannerView.startCamera();
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
mScannerView.stopCamera();
}
答案 0 :(得分:0)
尝试以下方法:
@Override
public void handleResult(Result result) {
Log.v("TAG", result.getText());
Log.v("TAG", result.getBarcodeFormat().toString());
String ResultString = result.getBarcodeFormat().toString();
Intent i = new Intent(this, Barcode_Activity.class);
i.putExtra("qrresult", ResultString);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Scan Result");
builder.setMessage(result.getText());
AlertDialog alert1 = builder.create();
alert1.show();
mScannerView.resumeCameraPreview(this);
}
在下一个活动中,您可以将结果显示为
Intent intent = getIntent();
String ResultString= intent.getExtras().getString("qrresult");
您也可以根据需要调用数据库。
希望有所帮助
答案 1 :(得分:0)
您可以将结果放在bundle
或SharedPreferences