Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- implementation 'com.google.zxing:core:2.2'
- implementation 'com.embarkmobile:zxing-android-minimal:1.2.1@aar'
- <activity
- android:name="com.google.zxing.client.android.CaptureActivity"
- android:configChanges="orientation|keyboardHidden"
- android:label="@string/app_name"
- android:screenOrientation="landscape"
- android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
- android:windowSoftInputMode="stateAlwaysHidden" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- <intent-filter>
- <action android:name="com.google.zxing.client.android.SCAN" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </activity>
- private void checkPermission() {
- // Verifica necessidade de verificacao de permissao
- if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
- if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
- Toast.makeText(this, "Não há permissão para utilizar a camera!", Toast.LENGTH_SHORT).show();
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.CAMERA},
- CODE_PERMISSION_CAMERA);
- } else {
- // Solicita permissao
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.CAMERA},
- CODE_PERMISSION_CAMERA);
- }
- }
- }
- private void openCamera(){
- Intent intent = new Intent("com.google.zxing.client.android.SCAN");
- // QR_CODE_MODE: QRCODE , ONE_D_MODE: Codigo de barras
- intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
- startActivityForResult(intent, 0);
- }
- public void onActivityResult(int requestCode, int resultCode, Intent intent) {
- if (requestCode == 0) {
- if (resultCode == Activity.RESULT_OK) {
- String contents = intent.getStringExtra("SCAN_RESULT");
- Toast.makeText(getApplicationContext(), contents, Toast.LENGTH_LONG).show();
- Log.i("CONTENT SCAN ", contents);
- } else if (resultCode == Activity.RESULT_CANCELED) {
- // Handle cancel
- }
- }
- }
Add Comment
Please, Sign In to add comment