Google Play 服务在 Android 2.3 Vision API 上崩溃

Google Play Services Crashes on Android 2.3 Vision API

我正在使用 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 播放服务指南 Android 2.3 应该被支持: https://developers.google.com/android/guides/setup

我也尝试释放一些 space 并按照 中的建议恢复出厂设置,但没有任何成功。

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

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

您将无法在 2.x 台设备上使用此功能。