Skip to content

Instantly share code, notes, and snippets.

@yamanetoshi
Created August 27, 2015 06:09
Show Gist options
  • Save yamanetoshi/4b7e0444ae09c5a18520 to your computer and use it in GitHub Desktop.
Save yamanetoshi/4b7e0444ae09c5a18520 to your computer and use it in GitHub Desktop.
IntentIntegrator (ZXing) Example
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// new IntentIntegrator(MainActivity.this).initiateScan(IntentIntegrator.ONE_D_CODE_TYPES);
// new IntentIntegrator(MainActivity.this).initiateScan(IntentIntegrator.ALL_CODE_TYPES);
new IntentIntegrator(MainActivity.this).initiateScan();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == IntentIntegrator.REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
String contents = intent.getStringExtra(Intents.Scan.RESULT);
String formatName = intent.getStringExtra(Intents.Scan.RESULT_FORMAT);
Log.d(TAG, "contents : " + contents);
Log.d(TAG, "formatName : " + formatName);
Toast.makeText(this, "contents : " + contents, Toast.LENGTH_LONG).show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment