WebView in Dialog gives exception on enabling Plugins in android - android-webview

I have followed example program given in below link for placing WebView in Dialog.
http://www.41post.com/4673/programming/android-creating-a-webview-dialog
Application is working perfectly fine. But if I enable plugins (setPlauginsEnabled(true)); application gives exception.
Issue exists only for websites with flash content.
Below is the part of code,
*
webView.getSettings().setPluginsEnabled(true);
//Set the user agent
webView.getSettings().setUserAgentString("AndroidWebView");
//Clear the cache
webView.clearCache(true);
//Make the webview load the specified URL
webView.loadUrl("http://www.coca-cola.com/en/index.html");
*
Below is the code trace,
E/AndroidRuntime( 1868): FATAL EXCEPTION: main
E/AndroidRuntime( 1868): java.lang.ClassCastException: android.view.ContextThemeWrapper cannot be cast to android.app.Activity
E/AndroidRuntime( 1868): at com.adobe.flashplayer.FlashPaintSurface.getBrowserActivity(FlashPaintSurface.java:650)
E/AndroidRuntime( 1868): at com.adobe.flashplayer.FlashPaintSurface$2.surfaceCreated(FlashPaintSurface.java:208)
E/AndroidRuntime( 1868): at android.view.SurfaceView.updateWindow(SurfaceView.java:533)
E/AndroidRuntime( 1868): at android.view.SurfaceView.access$000(SurfaceView.java:81)
E/AndroidRuntime( 1868): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
E/AndroidRuntime( 1868): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)
E/AndroidRuntime( 1868): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1617)
E/AndroidRuntime( 1868): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2446)
E/AndroidRuntime( 1868): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1868): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 1868): at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime( 1868): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1868): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 1868): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 1868): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 1868): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 1117): Force finishing activity fortyonepost.com.webviewdialog/.WebViewDialogActivity

Issue resolved;
Create FrameLayout inside WebViewDialog.xml & add WebView in to FrameLayout.
webView = new WebView(this);
wrapper = (FrameLayout)webViewDialog.findViewById(R.id.webview_wrapper);
wrapper.addView(webView);
If WebView is attached to WebView layout, flash plugin will create problems.

Related

Lost connection to device flutter [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 15 hours ago.
Improve this question
when i use this _serviceEnabled = await location.requestService();
to enable location in emulator i get this error
///////////////////////////////////////////////////////
but if the location is on it will run
///////////////////////////////////////////
and i updated all thinks
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
D/FlutterGeolocator( 9756): Attaching Geolocator to activity
D/FlutterGeolocator( 9756): Creating service.
D/FlutterGeolocator( 9756): Binding to location service.
D/FlutterLocationService( 9756): Creating service.
D/FlutterLocationService( 9756): Binding to location service.
D/FlutterGeolocator( 9756): Geolocator foreground service connected
D/FlutterGeolocator( 9756): Initializing Geolocator services
D/FlutterGeolocator( 9756): Flutter engine connected. Connected engine count 1
Connecting to VM Service at ws://127.0.0.1:54470/XMa3BfDCzxo=/ws
E/AndroidRuntime( 9756): FATAL EXCEPTION: main
E/AndroidRuntime( 9756): Process: com.example.map, PID: 9756
E/AndroidRuntime( 9756): java.lang.IncompatibleClassChangeError: Found interface com.google.android.gms.location.SettingsClient, but class was expected (declaration of 'com.google.android.gms.location.SettingsClient' appears in /data/app/~~nx2Rt28p5mjXBK5Owysq_A==/com.example.map-qaIT0zpByZNHS_Yr4lvDaA==/base.apk)
E/AndroidRuntime( 9756): at com.lyokone.location.FlutterLocation.requestService(FlutterLocation.java:388)
E/AndroidRuntime( 9756): at com.lyokone.location.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:55)
E/AndroidRuntime( 9756): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/AndroidRuntime( 9756): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/AndroidRuntime( 9756): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/AndroidRuntime( 9756): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/AndroidRuntime( 9756): at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime( 9756): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 9756): at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime( 9756): at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime( 9756): at android.app.ActivityThread.main(ActivityThread.java:7839)
E/AndroidRuntime( 9756): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 9756): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime( 9756): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
I/Process ( 9756): Sending signal. PID: 9756 SIG: 9
Lost connection to device.
Exited (sigterm)
to enable gps in device

How to resolve java.lang.NoClassDefFoundError errors in flutter?

When I run the app from flutter to the Android simulator, the following error is returned, and it does not run, I don't know what the problem is, please advise on the error.
Launching lib/main.dart on Android SDK built for arm64 in debug mode...
lib/main.dart:1
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:57149/NUW2Tq4P_Hg=/ws
E/AndroidRuntime( 8510): FATAL EXCEPTION: main
E/AndroidRuntime( 8510): Process: com.example.qnsdk_example, PID: 8510
E/AndroidRuntime( 8510): java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/localbroadcastmanager/content/LocalBroadcastManager;
E/AndroidRuntime( 8510): at com.yolanda.health.qnblesdk.out.QNBleApi.setBleDeviceDiscoveryListener(QNBleApi.java:787)
E/AndroidRuntime( 8510): at com.example.qnsdk.QNSdkPlugin.setBleDeviceDiscoveryListener(QNSdkPlugin.kt:146)
E/AndroidRuntime( 8510): at com.example.qnsdk.QNSdkPlugin.onMethodCall(QNSdkPlugin.kt:82)
E/AndroidRuntime( 8510): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/AndroidRuntime( 8510): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:178)
E/AndroidRuntime( 8510): at io.flutter.embedding.engine.dart.DartMessenger.lambda$handleMessageFromDart$0$DartMessenger(DartMessenger.java:206)
E/AndroidRuntime( 8510): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$R4HPk6oFVb-i-YR_PN9YE6kqx1I.run(Unknown Source:12)
E/AndroidRuntime( 8510): at android.os.Handler.handleCallback(Handler.java:883)
E/AndroidRuntime( 8510): at android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime( 8510): at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime( 8510): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime( 8510): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 8510): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime( 8510): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/AndroidRuntime( 8510): Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.localbroadcastmanager.content.LocalBroadcastManager" on path: DexPathList[[zip file "/data/app/com.example.qnsdk_example-cDdo9nfJTxqNGC_B2Gxa2g==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.qnsdk_example-cDdo9nfJTxqNGC_B2Gxa2g==/lib/arm64, /data/app/com.example.qnsdk_example-cDdo9nfJTxqNGC_B2Gxa2g==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
E/AndroidRuntime( 8510): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
E/AndroidRuntime( 8510): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime( 8510): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime( 8510): ... 14 more
I/flutter ( 8510): initSDK 1108
I/Process ( 8510): Sending signal. PID: 8510 SIG: 9
Lost connection to device.
Exited (sigterm)
and in the sdk manager
android sdk command-line tools (latest)
I followed it because I had to check it, but the error does not go away and continues.
Try this:
Open Tools > SDK Manager
choose Appearance & Behavior > System Settings > Android SDK
Select SDK Tools
Check Android SDK Command-line tools and click ‘apply’.

Regular TensorFlow ops are not supported by this interpreter. Make sure you apply/link the Flex delegate before inference

I have a problem when running a tflite model in my image classification app project( flutter ).
I have converted my CNN model to a tflite model via the code below:
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_saved_model('/content/drive/MyDrive/CNN_Model/10.07.CNNmodel.100.92')
# converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_LATENCY]
converter.target_spec.supported_ops = [
tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.
tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.
]
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
I tested the output of the tflite model and believe that it was converted successful. But when I added to my dart file in my project by the code:
Future loadModel() async {
await Tflite.loadModel(
model: 'assets/tflite/converted_model.tflite',
labels: 'assets/tflite/labels.txt',
);
}
After I ran the main.dart, took a picture to test, I got these errors:
E/AndroidRuntime( 6189): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime( 6189): Process: com.hajaj_projects.cat_vs_dog, PID: 6189
E/AndroidRuntime( 6189): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime( 6189): at android.os.AsyncTask$4.done(AsyncTask.java:415)
E/AndroidRuntime( 6189): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime( 6189): at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime( 6189): at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime( 6189): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
E/AndroidRuntime( 6189): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime( 6189): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime( 6189): at java.lang.Thread.run(Thread.java:923)
E/AndroidRuntime( 6189): Caused by: java.lang.IllegalArgumentException: Internal error: Failed to run on the given Interpreter: Regular TensorFlow ops are not supported by this interpreter. Make sure you apply/link the Flex delegate before inference.
E/AndroidRuntime( 6189): Node number 21 (FlexAddV2) failed to prepare.
E/AndroidRuntime( 6189):
E/AndroidRuntime( 6189): at org.tensorflow.lite.NativeInterpreterWrapper.run(Native Method)
E/AndroidRuntime( 6189): at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:204)
E/AndroidRuntime( 6189): at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:374)
E/AndroidRuntime( 6189): at org.tensorflow.lite.Interpreter.run(Interpreter.java:332)
E/AndroidRuntime( 6189): at sq.flutter.tflite.TflitePlugin$RunModelOnImage.runTflite(TflitePlugin.java:504)
E/AndroidRuntime( 6189): at sq.flutter.tflite.TflitePlugin$TfliteTask.doInBackground(TflitePlugin.java:471)
E/AndroidRuntime( 6189): at sq.flutter.tflite.TflitePlugin$TfliteTask.doInBackground(TflitePlugin.java:445)
E/AndroidRuntime( 6189): at android.os.AsyncTask$3.call(AsyncTask.java:394)
E/AndroidRuntime( 6189): at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime( 6189): ... 4 more
I/Process ( 6189): Sending signal. PID: 6189 SIG: 9
Lost connection to device.
When I removed the Normalization layer in my CNN model then converted it again, the app runs smoothly. But removing Normalization model decreased lots of my model accuracy.
I'm new to flutter. By any chance, has anybody encountered and resolved this before? Thanks for spending time.
dependencies {
implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly-SNAPSHOT'
// This dependency adds the necessary TF op support.
implementation 'org.tensorflow:tensorflow-lite-select-tf-ops:0.0.0-nightly-SNAPSHOT'
}
The converted model contains the Select TF ops. This means the model requires the Select TF op dependency.
If the above dependency is too big footprint, please consider creating a custom AAR through the selective build https://www.tensorflow.org/lite/guide/reduce_binary_size
See also https://www.tensorflow.org/lite/guide/ops_select.

Flutter StreamProvider with CloudFirestore causing error on Resume

Having a weird issue and cant seem to figure out if I have something setup wrong (new with Providers and streams) or if its a bug. Everything seems to work fine except when the app resumes after being backed out with the back button, on Android, and then restarted. Steps to reproduce:
Launch App
hit back button to close app (not just minimize)
Relaunch app
I get the following error:
D/AndroidRuntime( 3566): Shutting down VM
E/AndroidRuntime( 3566): FATAL EXCEPTION: main
E/AndroidRuntime( 3566): Process: com.crimsonowl.scryer, PID: 3566
E/AndroidRuntime( 3566): java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.invokeMethod(java.lang.String, java.lang.Object)' on a null object reference
E/AndroidRuntime( 3566): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$DocumentObserver.onEvent(CloudFirestorePlugin.java:429)
E/AndroidRuntime( 3566): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$DocumentObserver.onEvent(CloudFirestorePlugin.java:402)
E/AndroidRuntime( 3566): at com.google.firebase.firestore.DocumentReference.lambda$addSnapshotListenerInternal$2(com.google.firebase:firebase-firestore##21.3.0:504)
E/AndroidRuntime( 3566): at com.google.firebase.firestore.DocumentReference$$Lambda$3.onEvent(Unknown Source:6)
E/AndroidRuntime( 3566): at com.google.firebase.firestore.core.AsyncEventListener.lambda$onEvent$0(com.google.firebase:firebase-firestore##21.3.0:42)
E/AndroidRuntime( 3566): at com.google.firebase.firestore.core.AsyncEventListener$$Lambda$1.run(Unknown Source:6)
E/AndroidRuntime( 3566): at android.os.Handler.handleCallback(Handler.java:883)
E/AndroidRuntime( 3566): at android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime( 3566): at com.google.android.gms.internal.tasks.zzb.dispatchMessage(com.google.android.gms:play-services-tasks##17.0.2:6)
E/AndroidRuntime( 3566): at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime( 3566): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime( 3566): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 3566): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime( 3566): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process ( 3566): Sending signal. PID: 3566 SIG: 9
After a lot of debugging and trying to figure out what was causing it. Ive narrow the problem down to StreamProvider and my user data. In my main screen I load a stream of the Users data with this:
return FutureProvider.value(
value: Provider.of<IAPProvider>(context).initialize(),
child: StreamProvider<User>.value(
value: DatabaseProvider().streamUser(user.uid),
child: MainScreen(),
),
);
And the code for the stream is this:
Stream<User> streamUser(String id) {
return Firestore.instance
.collection(USER_COLLECTION)
.document(id)
.snapshots()
.map((snap) => User.fromFirestore(snap));
}
I figured out that anytime I try to write to the User document on the cloud firestore database the app crashes, but only when I have done the steps above. On the initial launch (and works fine if I relaunch after it crashes) everything works as expected. Something like this:
Firestore.instance.collection(USER_COLLECTION).document(user.uid).updateData({'last_login': FieldValue.serverTimestamp()});

Instrumentation run: java.lang.Error with Class init failed in Constructor error

I wrote an instrumentation test:
Exactly it shows an Verify error:
public WebViewActivityTest() {
super(WebViewActivity.class);
Constructor used:
W/dalvikvm( 858): Class init failed in Constructor.constructNative (Lcom/amazon/webviewapp/test/WebViewActivityTest;)
D/AndroidRuntime( 858): Shutting down VM
W/dalvikvm( 858): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
E/AndroidRuntime( 858): FATAL EXCEPTION: main
E/AndroidRuntime( 858): java.lang.VerifyError: com/amazon/webviewapp/test/WebViewActivityTest
E/AndroidRuntime( 858): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 858): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
E/AndroidRuntime( 858): at junit.framework.TestSuite.createTest(TestSuite.java:61)
E/AndroidRuntime( 858): at junit.framework.TestSuite.addTestMethod(TestSuite.java:294)
E/AndroidRuntime( 858): at junit.framework.TestSuite.addTestsFromTestCase(TestSuite.java:150)
E/AndroidRuntime( 858): at junit.framework.TestSuite.<init>(TestSuite.java:129)
E/AndroidRuntime( 858): at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:118)
E/AndroidRuntime( 858): at android.test.AndroidTestRunner.getTest(AndroidTestRunner.java:148)
E/AndroidRuntime( 858): at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:56)
E/AndroidRuntime( 858): at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:80)
E/AndroidRuntime( 858): at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:444)
E/AndroidRuntime( 858): at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:425)
E/AndroidRuntime( 858): at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:370)
E/AndroidRuntime( 858): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4382)
E/AndroidRuntime( 858): at android.app.ActivityThread.access$1300(ActivityThread.java:141)
E/AndroidRuntime( 858): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
E/AndroidRuntime( 858): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 858): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 858): at android.app.ActivityThread.main(ActivityThread.java:5039)
E/AndroidRuntime( 858): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 858): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 858): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 858): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 858): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 285): Error in app com.amazon.webviewapp running instrumentation ComponentInfo{com.amazon.webviewapp.test/android.test.InstrumentationTestRunner}:
W/ActivityManager( 285): java.lang.VerifyError
W/ActivityManager( 285): java.lang.VerifyError: com/amazon/webviewapp/test/WebViewActivityTest
D/AndroidRuntime( 848): Shutting down VM