livechat / chat-window-android

LiveChat mobile chat window for Android
https://developers.livechatinc.com/mobile/android/
MIT License
23 stars 28 forks source link

Allow open external link #50

Closed ArcherEmiya05 closed 3 years ago

ArcherEmiya05 commented 3 years ago

I tried to take a local copy of this project and one thing that our team noticed is that links within the chats can't be automatically open via another browser. We know that it has something to do with shouldOverrideUrlLoading in ChatWindowView.class but there is also a method handleUri(). What changes do we need to perform to allow link/uri intents so we can open a link via browser app. We do not want to break the existing logic of the handleUri() methods thus we ask for your guidance on this. This also could probably a feature request. We tried to change the code to adding an Intent and returning true on shouldOverrideUrlLoading but after returning in the app, the LiveChat windows become empty.

  `private boolean handleUri(WebView webView, final Uri uri) {
        String uriString = uri.toString();
        boolean facebookLogin = uriString.matches("https://.+facebook.+(/dialog/oauth\\?|/login\\.php\\?|/dialog/return/arbiter\\?).+");

        if (facebookLogin) {
            return false;
        } else {
            if (webViewPopup != null) {
                webViewPopup.setVisibility(GONE);
                removeView(webViewPopup);
                webViewPopup = null;
            }

            String originalUrl = webView.getOriginalUrl();

            if (uriString.equals(originalUrl) || isSecureLivechatIncDoamin(uri.getHost())){//uri.getHost().contains("secure-lc.livechatinc.com")) {
                return false;
            } else {
                if (chatWindowListener != null/* && chatWindowListener.handleUri(uri)*/) {
                    return true;
                }
                else {
                    try {
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        getContext().startActivity(intent);
                    }
                    catch (Exception e){
                        Toast.makeText(getContext(), "Error : " + e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }

                return true;
            }
        }
    }`
ArcherEmiya05 commented 3 years ago

Already fix it by replacing the last else statement

    ` else {
                if (chatWindowListener != null/* && chatWindowListener.handleUri(uri)*/) {
                    try {
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        getContext().startActivity(intent);
                    }
                    catch (Exception e){
                        e.printStackTrace();
                        Toast.makeText(getContext(), "Error : " + e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                    return true;
                }

                return true;
            }`
nomyzs commented 3 years ago

Hello @ArcherEmiya05 !

Thanks for reaching out and apologies for late response. Glad you made it work for you! Looking at your modified piece of code in your update makes me believe that in your case if you just specify your ChatWindowEventsListener and return false in your overwritten handleUri method this should work as intended.

Hope this helps

ArcherEmiya05 commented 3 years ago

Hello @ArcherEmiya05 !

Thanks for reaching out and apologies for late response. Glad you made it work for you! Looking at your modified piece of code in your update makes me believe that in your case if you just specify your ChatWindowEventsListener and return false in your overwritten handleUri method this should work as intended.

Hope this helps

Does this mean I can do the same without modifying ChatWindowView.class file or what I did is the only solution so far?

nomyzs commented 3 years ago

Yes, you should be able to do the same without modifying this library. Please note that new version is also available, v2.1.5 being the latest release.

nomyzs commented 3 years ago

Hoping above helped. Closing this for now, but please open another issue if you still facing this issue or found any others :)