[英]Zxing barcode scanner implementation intent
I've been looking everywhere regarding implementing a barcode scanner into my application/ I've already included the code which'll enable the user to scan if the Barcode scanner is installed but I now need something to prompt the user to download the application if it isn't already installed? 我一直在到处寻找有关在我的应用程序中实现条形码扫描仪的信息/我已经包含了使用户能够扫描是否已安装条形码扫描仪的代码,但是如果有以下情况,我现在需要一些提示用户下载应用程序的代码它尚未安装? I followed an example to get me this far. 我遵循了一个例子来使我走到这一步。
Here is my code 这是我的代码
package com.example.zxingscan;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
HandleClick hc = new HandleClick();
findViewById(R.id.butQR).setOnClickListener(hc);
}
private class HandleClick implements OnClickListener{
public void onClick(View arg0) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
switch(arg0.getId()){
case R.id.butQR:
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
break;
}
startActivityForResult(intent, 0); //Barcode Scanner to scan for us
}
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
TextView tvStatus=(TextView)findViewById(R.id.tvStatus);
TextView tvResult=(TextView)findViewById(R.id.tvResult);
if (resultCode == RESULT_OK) {
tvStatus.setText(intent.getStringExtra("SCAN_RESULT_FORMAT"));
tvResult.setText(intent.getStringExtra("SCAN_RESULT"));
} else if (resultCode == RESULT_CANCELED) {
tvStatus.setText("Press a button to start a scan.");
tvResult.setText("Scan cancelled.");
}
}
}
}
First of all create a dialog that briefly explains the situation and that suggests to install the free ZXing scanner app from Google Play. 首先,创建一个对话框,简要说明情况,并建议您从Google Play安装免费的ZXing扫描仪应用程序。 Add a Cancel
and an Install
button. 添加一个Cancel
和Install
按钮。 I'm not going to explain how to do that here. 我不会在这里解释如何做。 Just take a look at this AlertDialog.Builder tutorial for example. 例如,只需看一下AlertDialog.Builder教程 。
Upon user confirmation ( Install
button click) you just need to start the following intent: 在用户确认后(单击“ Install
按钮),您只需要启动以下意图:
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=com.google.zxing.client.android")));
market
protocol Uri
s can be used to open app detail pages from the Google Play market. market
协议Uri
可以用于打开Google Play市场中的应用程序详细信息页面。 See this Android documentation page for more information. 有关更多信息,请参见此Android文档页面 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.