I am able to invoke the barcode scanner via intents, but when I try to capture the values returned by the scan based on this, I get the following errors when trying to build the solution.
- Android.Content.Intent' does not contain a definition for 'getStringExtras' and no extension method 'getStringExtras' accepting a first argument of type 'Android.Content.Intent' could be found (are you missing a using directive or an assembly reference?)
- The name 'RESULT_CANCELED' does not exist in the current context
- The name 'RESULT_OK' does not exist in the current context
Here is my code for both invoking the scanner and trying to return results. Click event is in onCreate. onActivityResult is a method in the same.cs, same class, same namespace as the scan.Click event.
Button scan = (Button)FindViewById(Resource.Id.scan);
scan.Click += (o, e) =>
{
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.SetPackage("com.google.zxing.client.android");
intent.PutExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
StartActivityForResult(intent, 0);
};
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if (requestCode == 0)
{
if (resultCode == RESULT_OK)
{
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
}
else if (resultCode == RESULT_CANCELED)
{
}
}
}