Я использую подмножество приведенного примера здесь и документы Firebase OCR. Я получаю сокет закрыт во время запуска Cloud Text Recognition с использованием Firebase ML Kit. Запуск этого на устройстве с Android Pie.
Я попытался очистить кэш сервисов Google Play, перезагрузить устройство (работает 1 раз), создать конфигурацию безопасности сети, позволяющую отправлять / получать HTTP-запросы от здесь
Создание растрового изображения из Asset и передача его в runCloudTextRecognition
Манифест Android
<uses-permission android:name="android.permission.INTERNET" />
<application>
<meta-data
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
android:value="ocr" />
</application>
runCloudTextRecognition и getBitmapFromAsset
public static Bitmap getBitmapFromAsset(Context context, String filePath) {
AssetManager assetManager = context.getAssets();
InputStream istr;
Bitmap bitmap = null;
try {
istr = assetManager.open(filePath);
bitmap = BitmapFactory.decodeStream(istr);
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
private void runCloudTextRecognition(Bitmap mSelectedImage) {
//mCloudButton.setEnabled(false);
FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(mSelectedImage);
final FirebaseVisionTextRecognizer recognizer = FirebaseVision.getInstance()
.getCloudTextRecognizer();
recognizer.processImage(image)
.addOnSuccessListener(
new OnSuccessListener<FirebaseVisionText>() {
@Override
public void onSuccess(FirebaseVisionText texts) {
//mCloudButton.setEnabled(true);
Log.e("CloudOCR_Success",texts.getText());
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Task failed with an exception
//mCloudButton.setEnabled(true);
e.printStackTrace();
try {
recognizer.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
}
LogCat
E/ImageAnnotatorTask: batchAnnotateImages call failed with exception:
java.net.SocketTimeoutException: timeout
at com.android.okhttp.okio.Okio$3.newTimeoutException(Okio.java:212)
at com.android.okhttp.okio.AsyncTimeout.exit(AsyncTimeout.java:261)
at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:215)
at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:306)
at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:300)
at com.android.okhttp.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196)
at com.android.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:186)
at com.android.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737)
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:609)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:471)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:538)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:26)
at com.google.android.gms.internal.firebase_ml.zzgd.<init>(Unknown Source:5)
at com.google.android.gms.internal.firebase_ml.zzga.zzfg(Unknown Source:43)
at com.google.android.gms.internal.firebase_ml.zzfk.zzfa(Unknown Source:131)
at com.google.android.gms.internal.firebase_ml.zzer.zzei(Unknown Source:51)
at com.google.android.gms.internal.firebase_ml.zzqf.zza(Unknown Source:68)
at com.google.android.gms.internal.firebase_ml.zzqg.zza(Unknown Source:23)
at com.google.android.gms.internal.firebase_ml.zznt.call(Unknown Source:4)
at com.google.android.gms.internal.firebase_ml.zznn.zza(Unknown Source:30)
at com.google.android.gms.internal.firebase_ml.zznq.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.google.android.gms.internal.firebase_ml.zzf.dispatchMessage(Unknown Source:6)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.net.SocketException: socket is closed
at com.android.org.conscrypt.ConscryptFileDescriptorSocket$SSLInputStream.read(ConscryptFileDescriptorSocket.java:551)
at com.android.okhttp.okio.Okio$2.read(Okio.java:136)
at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:306)
at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:300)
at com.android.okhttp.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196)
at com.android.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:186)
at com.android.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737)
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:609)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:471)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:538)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:26)
at com.google.android.gms.internal.firebase_ml.zzgd.<init>(Unknown Source:5)
at com.google.android.gms.internal.firebase_ml.zzga.zzfg(Unknown Source:43)
at com.google.android.gms.internal.firebase_ml.zzfk.zzfa(Unknown Source:131)
at com.google.android.gms.internal.firebase_ml.zzer.zzei(Unknown Source:51)
at com.google.android.gms.internal.firebase_ml.zzqf.zza(Unknown Source:68)
at com.google.android.gms.internal.firebase_ml.zzqg.zza(Unknown Source:23)
at com.google.android.gms.internal.firebase_ml.zznt.call(Unknown Source:4)
at com.google.android.gms.internal.firebase_ml.zznn.zza(Unknown Source:30)
at com.google.android.gms.internal.firebase_ml.zznq.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.google.android.gms.internal.firebase_ml.zzf.dispatchMessage(Unknown Source:6)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:65)