androidgoogle-play-servicesandroid-2.3-gingerbreadgoogle-visionandroid-vision

Google Play Services Crashes on Android 2.3 Vision API


I'm using the Android Vision API for a QR-code-scanner which works fine on several Android devices and versions, except for Android 2.3.x devices. When I open the QR-code-scanner a dialog is shown that the google-play-services crashes. In the Logcat I see the following error.

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)

This is the code of my fragment

@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);
  }
}

according to the Google Play Services guide Android 2.3 should be supported: https://developers.google.com/android/guides/setup

I also tried freeing up some space and did a factory reset as suggested in: Google Vision barcode library not found without any succes.

Does anybody know what i'm doing wrong?


Solution

  • It looks like this particular API relies upon SharedPreferences.getStringSet(), which according to the Android docs, was only introduced in API 11 (Android v3.0 Honeycomb).

    You won't be able to use this on 2.x devices.