朋友们,我实现的应用程序是我的应用程序扫描qr代码,我使用com.google.zxing:core:3.2.1库,下面是我的gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.pkg"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.+'
compile 'com.android.support:design:22.+'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'//Add dependency
compile 'com.google.zxing:core:3.2.1'
}
我打电话扫描下面的条形码
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
IntentIntegrator integrator = new IntentIntegrator(ActivitySubTask.this);
scanid=mArrayListGetSubLocations.get(i).getSubid();
Log.d("scanid ",String.valueOf(scanid));
integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
integrator.setPrompt("Scan");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(false);
integrator.initiateScan();
}
});
上面的代码在4.0到5.1版本的设备上工作正常,但是当我在6.0版本的设备中测试它是崩溃应用程序,下面是我的错误消息来自我的Logcat
java.lang.NoSuchMethodError: No static method checkSelfPermission(Landroid/content/Context;Ljava/lang/String;)I in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/pkg.android.rootways.cleaning-1/base.apk)
at com.journeyapps.barcodescanner.CaptureManager.openCameraWithPermission(CaptureManager.java:233)
at com.journeyapps.barcodescanner.CaptureManager.onResume(CaptureManager.java:221)
at com.journeyapps.barcodescanner.CaptureActivity.onResume(CaptureActivity.java:42)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1258)
at android.app.Activity.performResume(Activity.java:6312)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3092)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
修改
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
答案 0 :(得分:0)
我通过从22
制作版本23来改变gradle文件来制作解决方案apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.pkg"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.+'
compile 'com.android.support:design:23.+'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'//Add dependency
compile 'com.google.zxing:core:3.2.1'
}
答案 1 :(得分:0)
在Android 6上,他们实现了获取权限的新方法
您必须在运行时提出要求