2

我正在将 Android Vision API 用于 QR 码扫描仪,它可以在多个 Android 设备和版本上正常工作,但 Android 2.3.x 设备除外。当我打开 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 条码库未找到但没有任何成功。

有人知道我在做什么错吗?

4

1 回答 1

2

看起来这个特定的 API 依赖于SharedPreferences.getStringSet(),根据Android 文档,它仅在 API 11(Android v3.0 Honeycomb)中引入。

您将无法在 2.x 设备上使用它。

于 2015-09-08T13:00:50.200 回答