用zxing库扫描二维码后弹出神秘对话框
Misterious dialog pops up after to scan a qr code with zxing library
我正在构建一个简单的 android 应用程序,用于使用 zxing 作为外部库扫描二维码。一切正常,直到我扫描包含 link 的二维码。之后弹出如下信息:Open link to the clipboard?
即使在我关闭应用程序后,此消息仍保留在屏幕上,我必须重新启动 phone 才能使消息消失。
我不知道为什么会这样。下面是打印屏幕和我的代码。
我不知道这是否相关,但我项目中的目标 api 是 api 级别 23,我设备的 api 级别是 api 级别 21.
misterious dialog bellow screen after to scan
and remains after closing the application
build.gradle [应用模块]
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>
调用zxing captureactivity扫描二维码的代码段。 [在 MainAtivity 的 onCreate 中]
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
}
}
});
和onActivityResult方法
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);
}
}
谢谢大家的帮助!
为了解决我的问题,我重写了二维码读取方法。
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();
}
我正在构建一个简单的 android 应用程序,用于使用 zxing 作为外部库扫描二维码。一切正常,直到我扫描包含 link 的二维码。之后弹出如下信息:Open link to the clipboard? 即使在我关闭应用程序后,此消息仍保留在屏幕上,我必须重新启动 phone 才能使消息消失。 我不知道为什么会这样。下面是打印屏幕和我的代码。 我不知道这是否相关,但我项目中的目标 api 是 api 级别 23,我设备的 api 级别是 api 级别 21.
misterious dialog bellow screen after to scan
and remains after closing the application
build.gradle [应用模块]
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>
调用zxing captureactivity扫描二维码的代码段。 [在 MainAtivity 的 onCreate 中]
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
}
}
});
和onActivityResult方法
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);
}
}
谢谢大家的帮助!
为了解决我的问题,我重写了二维码读取方法。
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();
}