我正在使用Android Vision API进行QR码扫描,除了Android 2.3.x设备外,它在几个Android设备和版本上运行良好。当我打开QR码扫描仪时,会显示一个对话框,表明google-play-services崩溃了。在Logcat中,我看到以下错误。
FATAL EXCEPTION: AsyncOperationService[VisionDependencyIntentService]
java.lang.NoSuchMethodError: android.content.SharedPreferences.getStringSet
at com.google.android.gms.vision.service.VisionDependencyIntentService.b(SourceFile:185)
at com.google.android.gms.vision.service.VisionDependencyIntentService.a(SourceFile:174)
at com.google.android.gms.vision.service.a.a.a(SourceFile:45)
at com.google.android.gms.chimera.f.run(SourceFile:179)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
这是我片段的代码
@Override
public void onViewCreated(View view, Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
Activity activity = getActivity();
preview = (CameraSourcePreview) view.findViewById(R.id.preview);
int connectionResult = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity);
if (connectionResult == ConnectionResult.SUCCESS)
{
// create a barcode detector.
BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(activity).setBarcodeFormats(Barcode.QR_CODE)
.build();
// create a processor to filter qr-codes and a tracker to handle the selected qr-code.
barcodeDetector.setProcessor(new QrCodeProcessor(barcodeDetector, new QrCodeTracker(this)));
if (barcodeDetector.isOperational())
{
// Creates and starts the camera.
cameraSource = new CameraSource.Builder(activity, barcodeDetector)
.setFacing(CameraSource.CAMERA_FACING_BACK).setRequestedPreviewSize(1600, 1024)
.setRequestedFps(15.0f).build();
}
else
{
showAlert(R.string.QrCodeScanner_alert_play_services_not_operational_header,
R.string.QrCodeScanner_alert_play_services_not_operational_body);
}
}
else
{
PlatformUtil.handlePlayServicesError(activity, connectionResult);
}
}
根据Google Play服务指南,应支持Android 2.3: https://developers.google.com/android/guides/setup
我还尝试释放一些空间并按照Google Vision barcode library not found中的建议重置工厂,但没有任何成功。
有人知道我做错了吗?
答案 0 :(得分:2)
看起来这个特定的API依赖于SharedPreferences.getStringSet()
,根据Android docs,它仅在API 11(Android v3.0 Honeycomb)中引入。
您将无法在2.x设备上使用此功能。