这是我的活动,我使用意图调用相机活动,我使用了谷歌播放服务中引入的条形码dector类Mobilevision请帮我找到我缺少的地方
public class MainActivity extends AppCompatActivity {
BarcodeDetector detector;
public void scanBarcode(View view){
try {
//detector = new BarcodeDetector.Builder(getApplicationContext()).setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE).build();
detector = new BarcodeDetector.Builder(getApplicationContext()).setBarcodeFormats(0).build();
if (!detector.isOperational())
Toast.makeText(MainActivity.this, "Error Occured Please Assure to Have Play Services", Toast.LENGTH_LONG).show();
else {
Toast.makeText(MainActivity.this, "Done", Toast.LENGTH_LONG).show();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
}catch (Exception e){
Toast.makeText(MainActivity.this,"Eror"+e.getMessage(),Toast.LENGTH_LONG).show();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onActivityResult(int requestCode,int replyCode,Intent data){
TextView textView = (TextView) findViewById(R.id.ContentWillAriveHere);
try {
Bitmap myBitmap = (Bitmap) data.getExtras().get("data");
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Barcode> barcode = detector.detect(frame);
Barcode barcode1 = barcode.valueAt(0);
textView.setText("Data = "+barcode1.rawValue);
}catch (Exception e){
textView.setText("Data = "+e.getMessage());
}
}
}