我已经按照教程将zxing集成到我的应用程序中并且效果很好,现在唯一的问题是当我扫描qr代码时没有启动,我是一个完整的新手,一些输入将是一个很大的帮助。 我的java是:
public class MainActivity extends Activity implements OnClickListener {
private Button scanBtn;
private TextView formatTxt, contentTxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scanBtn = (Button)findViewById(R.id.scan_button);
formatTxt = (TextView)findViewById(R.id.scan_format);
contentTxt = (TextView)findViewById(R.id.scan_content);
scanBtn.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onClick(View v){
//respond to clicks
if(v.getId()==R.id.scan_button){
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
scanIntegrator.initiateScan();
}
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanningResult != null) {
String scanContent = scanningResult.getContents();
String scanFormat = scanningResult.getFormatName();
formatTxt.setText("FORMAT: " + scanFormat);
contentTxt.setText("CONTENT: " + scanContent);
}else{
Toast toast = Toast.makeText(getApplicationContext(),
"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
}
我想启动浏览器,但我确定我错过了什么
答案 0 :(得分:1)
您实际上从未实际发布任何结果。如果您扫描了原来是网站链接的文本,则需要启动Web浏览器打开的意图。
在阅读结果后的活动结果中,您将执行以下操作:
Intent i= new Intent(Intent.ACTION_VIEW, Uri.parse(<INSERT URL>));
startActivity(i);
答案 1 :(得分:0)
从QR码获得字符串后,您需要按以下方式启动浏览器:
String url = "Url String";
Intent myIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
try {
// Start the activity
startActivity(myIntent);
this.finish();
} catch (ActivityNotFoundException e) {
// Raise on activity not found
Toast toast = Toast.makeText(context, "Browser not found.", Toast.LENGTH_SHORT);
}
希望这有帮助