在我的Android应用程序中,我已经包含了Zxing条形码扫描仪。 这很好,但一个小而重要的事情不起作用 我的应用程序只能在portait模式下使用。
如果我扫描一个水平的条形码(与红线相同),将会检测到条形码:
但是如果我扫描的条形码不是垂直的而是横向的,则不会检测到条形码: Show Image
这是我的条形码扫描仪的完整类。 你有什么想法我可以解决这个问题吗?
package me.dm7.barcodescanner.zxing.sample;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.google.zxing.Result;
import me.dm7.barcodescanner.zxing.ZXingScannerView;
public class Scanner extends AppCompatActivity implements ZXingScannerView.ResultHandler {
private static final String CAMERA_ID = "CAMERA_ID";
private ZXingScannerView mScannerView;
private int mCameraId = -1;
Intent intent;
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.barcode_scanner);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if(state != null) {
mCameraId = state.getInt(CAMERA_ID, -1);
} else {
mCameraId = -1;
}
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.ScannerLayout);
mScannerView = new ZXingScannerView(this);
relativeLayout.addView(mScannerView);
}
@Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this);
mScannerView.startCamera(mCameraId);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(CAMERA_ID, mCameraId);
}
@Override
public void handleResult(Result rawResult) {
Intent intent = new Intent(Scanner.this, LoadingData.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
@Override
public void onPause() {
super.onPause();
mScannerView.stopCamera();
}
}