Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android - Changed InAppBrowser.java so it works on modern devices #700

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PlanB007
Copy link

Platforms affected

Android

Motivation and Context

Fixes the issue of the camera not opening or not opening correctly, since this was a major issue. With a very long issue #328 multiple people working on this. With big thanks to @davidrevo for helping a lot! I'm just making the PR so people don't have to search any longer.

Description

Just making the PR so people don't have to search for issue #328

Testing

Tested One Plus 6T with the latest android

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change (How do I add them )
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@PlanB007
Copy link
Author

So I'm pretty new to making PR's to bigger projects, just made this PR since it was asked in the #328 If there is more info I can provide please let me know

@@ -260,25 +257,6 @@ else if (SYSTEM.equals(target)) {
else if (action.equals("close")) {
closeDialog();
}
else if (action.equals("loadAfterBeforeload")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have existing features such as this been removed?


if (lang.startsWith("en"))
{
title = "Choose the source";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding hard-coded strings such as this is undesirable - better to let the plugin user pass in a string in their locale

WebSettings settings = inAppWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setBuiltInZoomControls(showZoomControls);
settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

// Add postMessage interface
class JsObject {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another feature removed with no explanation why

@dpa99c
Copy link
Contributor

dpa99c commented Sep 1, 2020

This PR removes several existing features such as the postMessage API and beforeload event with no justification or
replacement functionality. There are also some questionable additions such as hard-coded strings in a handful of languages.

My feeling that in its current state this PR cannot be merged without breaking existing plugin functionality and the additional code is of questionable suitability for generic use by plugin users.

@PlanB007
Copy link
Author

Thanks for the reply! As mentioned, I made this PR based on issue #328 a lot of code is not made by myself, you should look into the issue for all the reasons and things 😄

@Pradeepg89
Copy link

Pradeepg89 commented Dec 1, 2020

Hi @PlanB007 @dpa99c i tried above inappbrowser java file in android 10 . And camera is opening correctly. But after selecting image using camera application is crashing with following error.

2020-12-01 13:27:44.107 30171-30171/? I/ordova.worksho: Late-enabling -Xcheck:jni
2020-12-01 13:27:44.167 30171-30171/? E/ordova.worksho: Unknown bits set in runtime_flags: 0x8000
2020-12-01 13:27:44.214 30171-30171/? E/RefClass: java.lang.reflect.InvocationTargetException
2020-12-01 13:27:44.561 30171-30171/com.cordova.workshop I/CordovaLog: Changing log level to DEBUG(3)
2020-12-01 13:27:44.561 30171-30171/com.cordova.workshop I/CordovaActivity: Apache Cordova native platform version 7.1.4 is starting
2020-12-01 13:27:44.561 30171-30171/com.cordova.workshop D/CordovaActivity: CordovaActivity.onCreate()
2020-12-01 13:27:44.628 30171-30171/com.cordova.workshop I/WebViewFactory: Loading com.google.android.webview version 87.0.4280.66 (code 428006633)
2020-12-01 13:27:44.793 30171-30171/com.cordova.workshop W/ordova.worksho: Accessing hidden method Landroid/os/Trace;->isTagEnabled(J)Z (greylist, reflection, allowed)
2020-12-01 13:27:44.794 30171-30171/com.cordova.workshop W/ordova.worksho: Accessing hidden method Landroid/os/Trace;->traceBegin(JLjava/lang/String;)V (greylist, reflection, allowed)
2020-12-01 13:27:44.794 30171-30171/com.cordova.workshop W/ordova.worksho: Accessing hidden method Landroid/os/Trace;->traceEnd(J)V (greylist, reflection, allowed)
2020-12-01 13:27:44.794 30171-30171/com.cordova.workshop W/ordova.worksho: Accessing hidden method Landroid/os/Trace;->asyncTraceBegin(JLjava/lang/String;I)V (greylist, reflection, allowed)
2020-12-01 13:27:44.794 30171-30171/com.cordova.workshop W/ordova.worksho: Accessing hidden method Landroid/os/Trace;->asyncTraceEnd(JLjava/lang/String;I)V (greylist, reflection, allowed)
2020-12-01 13:27:44.898 30171-30171/com.cordova.workshop I/cr_LibraryLoader: Loaded native library version number "87.0.4280.66"
2020-12-01 13:27:44.901 30171-30171/com.cordova.workshop I/cr_CachingUmaRecorder: Flushed 5 samples from 5 histograms.
2020-12-01 13:27:45.200 30171-30307/com.cordova.workshop W/chromium: [WARNING:dns_config_service_posix.cc(342)] Failed to read DnsConfig.
2020-12-01 13:27:45.465 30171-30171/com.cordova.workshop D/SystemWebViewEngine: CordovaWebView is running on device made by: realme
2020-12-01 13:27:45.478 30171-30171/com.cordova.workshop D/PluginManager: init()
2020-12-01 13:27:45.495 30171-30171/com.cordova.workshop D/CordovaWebViewImpl: >>> loadUrl(file:///android_asset/www/index.html)
2020-12-01 13:27:45.508 30171-30310/com.cordova.workshop W/ordova.worksho: Accessing hidden method Landroid/media/AudioManager;->getOutputLatency(I)I (greylist, reflection, allowed)
2020-12-01 13:27:45.522 30171-30310/com.cordova.workshop W/cr_media: Requires BLUETOOTH permission
2020-12-01 13:27:45.578 30171-30353/com.cordova.workshop E/GED: Failed to get GED Log Buf, err(0)
2020-12-01 13:27:45.579 30171-30353/com.cordova.workshop E/EGL-gift: Cannot load register apis
2020-12-01 13:27:45.591 30171-30171/com.cordova.workshop D/CordovaActivity: Started the activity.
2020-12-01 13:27:45.596 30171-30171/com.cordova.workshop D/CordovaActivity: Incoming Result. Request code = 120
2020-12-01 13:27:45.603 30171-30171/com.cordova.workshop D/CordovaInterfaceImpl: Sending activity result to plugin
2020-12-01 13:27:45.604 30171-30171/com.cordova.workshop D/InAppBrowser: onActivityResult (For Android >= 5.0)
2020-12-01 13:27:45.611 30171-30171/com.cordova.workshop D/AndroidRuntime: Shutting down VM
2020-12-01 13:27:45.615 30171-30171/com.cordova.workshop E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cordova.workshop, PID: 30171
java.lang.RuntimeException: Unable to resume activity {com.cordova.workshop/com.cordova.workshop.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=120, result=-1, data=null} to activity {com.cordova.workshop/com.cordova.workshop.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void android.webkit.ValueCallback.onReceiveValue(java.lang.Object)' on a null object reference
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4541)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4577)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:181)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:102)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2230)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7817)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1027)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=120, result=-1, data=null} to activity {com.cordova.workshop/com.cordova.workshop.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void android.webkit.ValueCallback.onReceiveValue(java.lang.Object)' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:5200)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4524)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4577) 
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) 
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:181) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:102) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2230) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:237) 
at android.app.ActivityThread.main(ActivityThread.java:7817) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1027) 
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void android.webkit.ValueCallback.onReceiveValue(java.lang.Object)' on a null object reference
at org.apache.cordova.inappbrowser.InAppBrowser.onActivityResult(InAppBrowser.java:1127)
at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:159)
at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:359)
at android.app.Activity.dispatchActivityResult(Activity.java:8320)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5193)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4524) 
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4577) 
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) 
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:181) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:102) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2230) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:237) 
at android.app.ActivityThread.main(ActivityThread.java:7817) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1027) 
2020-12-01 13:27:45.617 30171-30353/com.cordova.workshop W/IMGSRV: glGetString:4397: Override GL_RENDERER PowerVR SGX Doma
2020-12-01 13:27:45.636 30171-30353/com.cordova.workshop I/chatty: uid=10292(com.cordova.workshop) Chrome_InProcGp identical 2 lines
2020-12-01 13:27:45.650 30171-30353/com.cordova.workshop W/IMGSRV: glGetString:4397: Override GL_RENDERER PowerVR SGX Doma
2020-12-01 13:27:45.693 30171-30171/com.cordova.workshop I/Process: Sending signal. PID: 30171 SIG: 9

Kindly help how to resolve above issue.

@NiklasMerz
Copy link
Member

Some overlap with #857 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants