import android.app.Activity; import android.os.Bundle; import android.content.BroadcastReceiver; import android.widget.Button; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.widget.TextView; import android.view.View; import com.clover.sdk.v1.Intents; import com.clover.sdk.v3.scanner.BarcodeScanner; import com.clover.sdk.v3.scanner.BarcodeResult; public class MainActivity extends Activity { private Button mBarcodeOnButton; private Button mBarcodeOffButton; private BarcodeScanner mBarcodeScanner; private TextView barcode_result; private BroadcastReceiver barcodeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { BarcodeResult barcodeResult = new BarcodeResult(intent); if (barcodeResult.isBarcodeAction()) { String barcode = barcodeResult.getBarcode(); barcode_result.setText("Result: " + barcode); } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mBarcodeScanner = new BarcodeScanner(this); } @Override protected void onResume() { super.onResume(); registerBarcodeScanner(); barcode_result = (TextView) findViewById(R.id.barcode_result); mBarcodeOnButton = (Button) findViewById(R.id.barcode_scan_on_button); mBarcodeOnButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle extras = new Bundle(); extras.putBoolean(Intents.EXTRA_SCAN_QR_CODE, true); # Checks for QR codes extras.putBoolean(Intents.EXTRA_SCAN_1D_CODE, true); # Checks for a standard barcode mBarcodeScanner.executeStartScan(extras); } }); mBarcodeOffButton = (Button) findViewById(R.id.barcode_scan_off_button); mBarcodeOffButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mBarcodeScanner.executeStopScan(null); } }); } @Override protected void onPause() { super.onPause(); unregisterBarcodeScanner(); } private void registerBarcodeScanner() { registerReceiver(barcodeReceiver, new IntentFilter(BarcodeResult.INTENT_ACTION)); } private void unregisterBarcodeScanner() { unregisterReceiver(barcodeReceiver); } }
This code seems to depend on some accompanying layout file. I get
error: cannot find symbol variable activity_mainand other errors when accessing `R.layout` or `R.id`. Could you share some accompanying layout file?
Seems like the example has changed over time. The current version is at https://github.com/clover/android-examples/blob/master/barcodereceiver/app/src/main/java/com/clover/example/barcodereceiver/app/MainActivity.java and has the accompanying layout resources.
1 Person is following this question.