我构建了一个简单的android应用程序,用于扫描使用zxing作为外部库的QR码。一切正常,直到我扫描包含链接的QR码。之后会弹出以下消息:打开指向剪贴板的链接? 即使关闭应用程序后,此消息仍保留在屏幕上,我必须重新启动手机才能消息消失。 我不知道为什么会这样。下面是打印屏幕和我的代码。 我不知道这是否相关,但是我的项目中的目标api是api level 23,而我的设备的api级别是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>
调用zxing捕获活动扫描QR码的代码部分。 [正在进行主动创作]
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);
}
}
我感谢大家的帮助!
答案 0 :(得分:0)
为了解决我的问题,我改写了qr代码读取方法。
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();
}