implementation of main class:
public class Main Activity extends Activity implements ZBarScannerView.ResultHandler {
private ZBarScannerView mscannerview ;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick1(View view){
mscannerview=new ZBarScannerView(this);
setContentView(mscannerview);
mscannerview.setResultHandler(this);
mscannerview.startCamera();
}
@Override public void onPause() {
super.onPause();
mscannerview.stopCamera();
}
@Override public void handleResult(Result result) {
Log.w("handleResult", result.getContents());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Scan result");
builder.setMessage(result.getContents());
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
}
错误:2-18 01:42:51.809 14705-14851 / com.anewapplication W / CameraBase:连接到摄像机时出错:0
它是Zbar库的一个简单实现,我的相机没有弹出扫描!帮帮我 !提前谢谢。
答案 0 :(得分:0)
您未在此代码中设置任何Button
来点击。因此,如果您直接从OnClickListener
xml
设置layout
,那么您应该将视图作为参数传递给将处理其在您的方法中看不到的点击事件的方法(你没有任何参数)。
你可以这样做:
public void onClick1(View v){
mscannerview=new ZBarScannerView(this);
setContentView(mscannerview);
mscannerview.setResultHandler(this);
mscannerview.startCamera();
}
并在你的布局中:
<Button android:onClick="onClick1"..... />