7 package com.google.appinventor.components.runtime;
9 import android.Manifest;
10 import android.app.Activity;
11 import android.content.ActivityNotFoundException;
12 import android.content.ComponentName;
13 import android.content.Intent;
37 @DesignerComponent(version = YaVersion.BARCODESCANNER_COMPONENT_VERSION,
38 description =
"Component for using the Barcode Scanner to read a barcode",
39 category = ComponentCategory.SENSORS,
41 iconName =
"images/barcodeScanner.png")
43 @UsesActivities(activities = {
44 @ActivityElement(name =
"com.google.zxing.client.android.AppInvCaptureActivity",
45 screenOrientation =
"landscape",
46 stateNotNeeded =
"true",
47 configChanges =
"orientation|keyboardHidden",
48 theme =
"@android:style/Theme.NoTitleBar.Fullscreen",
49 windowSoftInputMode =
"stateAlwaysHidden")
51 @UsesPermissions(permissionNames =
"android.permission.CAMERA")
52 @UsesLibraries(libraries =
"Barcode.jar,QRGenerator.jar")
56 private static final String SCAN_INTENT =
"com.google.zxing.client.android.SCAN";
57 private static final String LOCAL_SCAN =
"com.google.zxing.client.android.AppInvCaptureActivity";
58 private static final String SCANNER_RESULT_NAME =
"SCAN_RESULT";
59 private String result =
"";
60 private boolean useExternalScanner =
true;
62 private boolean havePermission =
false;
66 private int requestCode;
74 super(container.
$form());
75 this.container = container;
83 public String Result() {
91 @
SimpleFunction(description =
"Begins a barcode scan, using the camera. When the scan " +
92 "is complete, the AfterScan event will be raised.")
93 public
void DoScan() {
94 Intent intent =
new Intent(SCAN_INTENT);
97 if (!havePermission) {
102 public void HandlePermissionResponse(String permission,
boolean granted) {
108 Manifest.permission.CAMERA);
114 String packageName = container.
$form().getPackageName();
115 intent.setComponent(
new ComponentName(packageName,
"com.google.zxing.client.android.AppInvCaptureActivity"));
117 if (requestCode == 0) {
121 container.
$context().startActivityForResult(intent, requestCode);
122 }
catch (ActivityNotFoundException e) {
131 if (requestCode == this.requestCode && resultCode == Activity.RESULT_OK) {
132 if (data.hasExtra(SCANNER_RESULT_NAME)) {
133 result = data.getStringExtra(SCANNER_RESULT_NAME);
158 description =
"If true App Inventor will look for and use an external scanning" +
159 " program such as \"Bar Code Scanner.\"")
160 public
boolean UseExternalScanner() {
161 return useExternalScanner;
175 public
void UseExternalScanner(
boolean useExternalScanner) {
176 this.useExternalScanner = useExternalScanner;