Search code examples
androidzxing

Misterious dialog pops up after to scan a qr code with zxing library


I'm buildind a simple android aplication for to scan QR codes using zxing as external library. Everything works fine until I to scan a QR code that contains a link. After that pops up the follow message: Open link to the clipboard? And this message remains on the screen even after I close the application and I have to restart my phone to the message disappear. I have no idea why this is happening. Below is an print screen and my codes. I don't know if this is related, but the target api in my project is api level 23 and the api level of my device is api level 21.

misterious dialog bellow screen after to scan

and remains after closing the application

build.gradle [app module]

        apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.atriuz.myapplication"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    mavenCentral()

    maven {
        url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:design:23.2.0'
    // Zxing libraries
    compile 'com.embarkmobile:zxing-android-minimal:2.0.0@aar'
    compile 'com.embarkmobile:zxing-android-integration:2.0.0@aar'
    compile 'com.google.zxing:core:3.0.1'
}

Manifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.atriuz.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


    </application>

</manifest>

Code section that call zxing capture activity to scan QR code. [Is in onCreate of MainAtivity]

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");

        intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
        try {
            startActivityForResult(intent, 0);
        }catch (ActivityNotFoundException e) {
            mostrarMensagem();//some error message
        }

    }
});

And onActivityResult method

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0 && resultCode == Activity.RESULT_OK) {
        final String qrcode = intent.getStringExtra("SCAN_RESULT");
        TextView text=(TextView)findViewById(R.id.test);
        text.setText(qrcode);
    }
}

I thank you all for your help!


Solution

  • To solve my problem I had rewrite the qr code read method.

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                readQR(view);
            }
        });
    
        public void readQR(View view) {
            IntentIntegrator intent = new IntentIntegrator(this);
    
            intent.addExtra("PROMPT_MESSAGE", "Put qr code inside marked area");
            intent.addExtra("SCAN_WIDTH", 1000);
            intent.addExtra("SCAN_HEIGHT", 550);
    
            try {
    
                intent.initiateScan();
                //startActivityForResult(intent, 0);
            } catch (ActivityNotFoundException e) {
                showMessage();
            }
        }
    
        private void showMessage() {
        new AlertDialog.Builder(this)
                .setTitle("Do you want to install barcode scanner?")
                .setMessage("YouTo read a qr code you need to install zxin barcode scanner.")
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setPositiveButton("Install",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(ZXING_MARKET));
                                try {
                                    startActivity(intent);
                                } catch (ActivityNotFoundException e) { // If don't have play store
                                    intent = new Intent(Intent.ACTION_VIEW, Uri.parse(ZXING_DIRECT));
                                    startActivity(intent);
                                }
                            }
                        })
                .setNegativeButton("Cancell", null).show();
    
        }