Scan Barcode And qrcode Programmatically In Android Studio
Step 6: Opening new activity in android studio
Download 139.41 Kb.
|
- Bu sahifa navigatsiya:
- Step 7: Updating ScanActivity.java file
Step 6: Opening new activity in android studioTo open new activity in the android studio, click on File tab which is present at the left top bar. Now go to File->New->Activity->Empty Activity and place name of activity as ScanActivity. new activity Step 7: Updating ScanActivity.java file:Add below code to ScanActivity.java import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import com.google.zxing.Result; import me.dm7.barcodescanner.zxing.ZXingScannerView; public class ScanActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler{ private ZXingScannerView mScannerView; @Override public void onCreate(Bundle state) { super.onCreate(state); mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view setContentView(mScannerView); // Set the scanner view as the content view } @Override public void onResume() { super.onResume(); mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results. mScannerView.startCamera(); // Start camera on resume } @Override public void onPause() { super.onPause(); mScannerView.stopCamera(); // Stop camera on pause } @Override public void handleResult(Result rawResult) { // Do something with the result here // Log.v("tag", rawResult.getText()); // Prints scan results // Log.v("tag", rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.) MainActivity.tvresult.setText(rawResult.getText()); onBackPressed(); // If you would like to resume scanning, call this method below: //mScannerView.resumeCameraPreview(this); } } Note: We do not need to update activity_scan.xml file because we will open camera preview here so no need to do anything in the layout file. Download 139.41 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling