网站上的QR码直接在移动设备上扫描,然后自动在移动设备上打开网站,但是如何?
答案 0 :(得分:0)
答案 1 :(得分:0)
这是示例代码
依赖项:
compile 'com.google.zxing:core:3.2.1'
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
扫描按钮
scan_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
IntentIntegrator integrator=new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
integrator.setPrompt("Scann");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(false);
integrator.initiateScan();
}
});
onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
IntentResult result=IntentIntegrator.parseActivityResult(requestCode,resultCode,data);
if(result!=null)
{
if(result.getContents()==null)
{
Toast.makeText(this,"Error",Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(this,result.getContents(),Toast.LENGTH_LONG).show();
}
}
else {
super.onActivityResult(requestCode, resultCode, data);
}
}