Skip to content

Change from CordovaWebView to SystemWebView in latest Cordova not working #494

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

Closed
sandeep2244 opened this issue Sep 12, 2018 · 9 comments
Closed
Labels

Comments

@sandeep2244
Copy link

I stuck in my old version Android App based on Codova
I updated My Android App to latest version [email protected]

Now where i used CordovaWebView for for Webview in my app as follows

<org.apache.cordova.CordovaWebView
         android:id="@+id/cordovaWebCallWebView"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />

but it's not present in latest version of Cordova. So I changed to it by below lines

 <org.apache.cordova.engine.SystemWebView
 android:id="@+id/SystemWebView"
 android:layout_width="match_parent"
 android:layout_height="match_parent" />

where i am using WebRtc for my App So I used following method of SystemWebView Class

cwv.setWebChromeClient(new WebChromeClient() {

            @Override
            public void onPermissionRequest(final PermissionRequest request) { 
                javaToJavascript.webrtcCallLog("web.java", "permission asked is"+Arrays.deepToString(request.getResources()),0); //This logs the type of permission asked
                Log.i("The list of permission asked is ", Arrays.deepToString(request.getResources())); // this askes for android.webkit.resource.AUDIO_CAPTURE permission

                getActivity().runOnUiThread(new Runnable() {
                    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                    @Override
                    public void run() {
                        Log.i("Value Of the permission asked is ", request
                                .getOrigin().toString());

                        request.grant(request.getResources());

                    }
                });

            }
        });

Now i got runtime error in my Main java file regarding classCastException

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.simCard.web/com.simCard.web.WebCall}: java.lang.ClassCastException: com.simCard.web.WebCall$1 cannot be cast to org.apache.cordova.engine.SystemWebChromeClient

How to solve This error ? Please any ones help will be grateful

Thank you

@janpio janpio added the support label Sep 12, 2018
@janpio
Copy link
Member

janpio commented Sep 12, 2018

I updated My Android App to latest version [email protected]

This is not the latest version. 7.1.1 is.

@sandeep2244
Copy link
Author

I updated My Android App to latest version [email protected]

This is not the latest version. 7.1.1 is.

Its ok ,
But how to solve above issue

??

@brody4hire
Copy link

but it's not present in latest version of Cordova. So I changed to it by below lines

This looks like a departure from the instructions in https://cordova.apache.org/docs/en/latest/guide/platforms/android/webview.html, which would not be supported.

If you need support we do need you to upgrade to the latest version of Cordova Android, which is now 7.1.1. Here is the command to upgrade to the latest version of Cordova Android:

cordova platform add android@latest

In case the instructions in https://cordova.apache.org/docs/en/latest/guide/platforms/android/webview.html do not work for you please post a minimal, complete demo project.

@sandeep2244
Copy link
Author

@brodybits @janpio
I updated to 7.1.1 And its not working

Because of CordovaWebView is now Interface not a Class, we cant use it so,

<org.apache.cordova.CordovaWebView
    android:id="@+id/tutorialView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Now changing to SystemWebView Class

I replaced it with

<org.apache.cordova.engine.SystemWebView
 android:id="@+id/SystemWebView"
 android:layout_width="match_parent"
 android:layout_height="match_parent" />

Now Problem is ,
there is function of SystemWebView.java (class)
setWebChromeClient()

public void setWebChromeClient(WebChromeClient client) {
        chromeClient = (SystemWebChromeClient)client;
        super.setWebChromeClient(client);
    }

And I override setWebChromeClient() in my main class(WebCall.java)

which i defined above in my question

And

I got Error Regarding Class Cast Exception
Which i defined in my question

In Previous Version They using CordovaWebView And I checked They Dont Cast It

below is the function for previous version

 public void setWebChromeClient(CordovaChromeClient client) {
        this.chromeClient = client;
        super.setWebChromeClient(client);
    }

So How to Solve it

Thank You

@janpio
Copy link
Member

janpio commented Sep 14, 2018

The webview documentation seems to be outdated in general. If you figure it out, please make sure to create a PR fixing the documentation to match the actual reality. Thank you!

@jcesarmobile
Copy link
Member

This is not a cordova-android issue, it's a cordova-docs issue.
The embedded workflow has been broken/undocumented for a long time, you can take a look at this two PRs that tried to document it, but in the end were closed. They both helped me to embed the webview long time ago. Also check the comments.
apache/cordova-docs#498
apache/cordova-docs#544

Closing this as there is a cordova-docs issue already linked.

@brody4hire
Copy link

Closing this as there is a cordova-docs issue already linked.

apache/cordova-docs#884

@martinhorvath
Copy link

I had a hard time with the documentation and tried to reflect my findings in this update: apache/cordova-docs@6dc8836

Can somebody check if this is useful for others?

@brody4hire
Copy link

[...] tried to reflect my findings in this update: apache/cordova-docs@6dc8836

My response is in apache/cordova-docs#884 (comment). In short a pull request would be really appreciated.

I would prefer that we keep further discussion in apache/cordova-docs#884 instead of this closed issue.

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

No branches or pull requests

5 participants