googlesamples / android-vision

Deprecated: The Mobile Vision API is now a part of ML Kit: Check out this repo:
https://github.com/firebase/quickstart-android/tree/master/mlkit
Apache License 2.0
2.93k stars 1.73k forks source link

Ocr-Complete project crashes on text detection if minSdkVersion is below 21 #113

Open mrigankdembla opened 7 years ago

mrigankdembla commented 7 years ago

Hi, I just downloaded and ran ocr-complete project in my device which is android 4.4( below api level 21) and it crashed due to an issue which is because on detection of text, according to code text will be converted to speech but tts(texttospeech) doesn't work below api level 21. So instead of directly converting text to speech, we can avoid the crash if we can check the sdk version of the device in which app is being run.

So according to this file :- https://github.com/googlesamples/android-vision/blob/master/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity.java

On line number 351 , in onTap function, we have :-

tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT");

we can change it to

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                    tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT");
else
                Toast.makeText(this,text.getValue(),Toast.LENGTH_SHORT).show();

By this we can show the detected text on user tap by toast message on devices below android 5.0 and for android devices having android lollipop and above, the detected text can be converted to speech.

Please let me know your views on this suggestion. Thanks.

mrigankdembla commented 7 years ago

@mbg1 please check this fix.

monajafi commented 7 years ago

the text recognizer is not available in api 17. Is this related to google play services version or another fix available for this