Java Code Examples for android.webkit.WebView#getUrl()

The following examples show how to use android.webkit.WebView#getUrl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GameWebView.java    From kcanotify_h5-master with GNU General Public License v3.0 6 votes vote down vote up
private void detectAndHandleLoginError(WebView view, SharedPreferences prefs) {
    // Only for DMM
    if(view.getUrl() != null && view.getUrl().equals("http://www.dmm.com/top/-/error/area/") && prefs.getBoolean("change_cookie_start", false) && changeCookieCnt++ < 5) {
        Log.i("KCVA", "Change Cookie");

        new Handler().postDelayed(new Runnable(){
            public void run() {
                Set<Map.Entry<String, String>> dmmCookieMapSet = gameActivity.dmmCookieMap.entrySet();
                for (Map.Entry<String, String> dmmCookieMapEntry : dmmCookieMapSet) {
                    view.evaluateJavascript("javascript:document.cookie = '" + dmmCookieMapEntry.getKey() + "';", new ValueCallback<String>() {
                        @Override
                        public void onReceiveValue(String value) {
                            Log.i("KCVA", value);
                        }
                    });
                }
                view.loadUrl(GameConnection.DMM_START_URL);
            }
        }, 5000);
    }
}
 
Example 2
Source File: a.java    From letv with Apache License 2.0 6 votes vote down vote up
public boolean a(WebView webView, String str) {
    f.b(b, "-->canHandleUrl---url = " + str);
    if (str == null || !Uri.parse(str).getScheme().equals("jsbridge")) {
        return false;
    }
    ArrayList arrayList = new ArrayList(Arrays.asList((str + "/#").split("/")));
    if (arrayList.size() < 6) {
        return false;
    }
    String str2 = (String) arrayList.get(2);
    String str3 = (String) arrayList.get(3);
    List subList = arrayList.subList(4, arrayList.size() - 1);
    a aVar = new a(webView, 4, str);
    webView.getUrl();
    a(str2, str3, subList, aVar);
    return true;
}
 
Example 3
Source File: GameWebView.java    From kcanotify_h5-master with GNU General Public License v3.0 5 votes vote down vote up
private void detectGameStartAndFit(WebView view) {
    if (view.getUrl() != null && view.getUrl().equals(hostNameOoi)) {
        fitGameLayout();
    }
    if (view.getUrl() != null && view.getUrl().equals(GameConnection.DMM_START_URL)) {
        fitGameLayout();
    }
}
 
Example 4
Source File: MainFragment.java    From chromium-webview-samples with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get reference of WebView from layout/activity_main.xml
    mWebView = (WebView) rootView.findViewById(R.id.fragment_main_webview);

    // Add Javascript Interface, this will expose "window.NotificationBind"
    // in Javascript
    mWebView.addJavascriptInterface(
            new NotificationBindObject(getActivity().getApplicationContext()),
            "NotificationBind");

    setUpWebViewDefaults(mWebView);

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        // Restore the previous URL and history stack
        mWebView.restoreState(savedInstanceState);
    }

    // Prepare the WebView and get the appropriate URL
    String url = prepareWebView(mWebView.getUrl());

    // Load the local index.html file
    if(mWebView.getUrl() == null) {
        mWebView.loadUrl(url);
    }

    return rootView;
}
 
Example 5
Source File: LightningChromeClient.java    From JumpGo with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void onReceivedTitle(@Nullable WebView view, @Nullable String title) {
    if (title != null && !title.isEmpty()) {
        mLightningView.getTitleInfo().setTitle(title);
    } else {
        mLightningView.getTitleInfo().setTitle(mActivity.getString(R.string.untitled));
    }
    mUIController.tabChanged(mLightningView);
    if (view != null && view.getUrl() != null) {
        mUIController.updateHistory(title, view.getUrl());
    }
}
 
Example 6
Source File: SimplicityWebViewClient.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
@Override
public void onLoadResource(WebView view, String url){
    super.onLoadResource(view, url);
    if (view != null && view.getUrl().contains("https://")) {
        mSecure.setImageDrawable(ContextCompat.getDrawable(mainView.getContext(), R.drawable.ic_secure_white));
        mSecure.setVisibility(View.VISIBLE);
    }else{
        mSecure.setImageDrawable(ContextCompat.getDrawable(mainView.getContext(), R.drawable.ic_unsecure_white));
        mSecure.setVisibility(View.VISIBLE);
    }
    if (mRefresh!= null || mStop !=null) {
        if (UserPreferences.getBoolean("dark_mode", false)) {
            mRefresh.setColorFilter(ContextCompat.getColor(SimplicityApplication.getContextOfApplication(), R.color.white), PorterDuff.Mode.SRC_IN);
            mStop.setColorFilter(ContextCompat.getColor(SimplicityApplication.getContextOfApplication(), R.color.white), PorterDuff.Mode.SRC_IN);
        } else {
            mRefresh.setColorFilter(ContextCompat.getColor(SimplicityApplication.getContextOfApplication(), R.color.dark), PorterDuff.Mode.SRC_IN);
            mStop.setColorFilter(ContextCompat.getColor(SimplicityApplication.getContextOfApplication(), R.color.dark), PorterDuff.Mode.SRC_IN);
        }
        if (isLoading) {
            mStop_rel.setVisibility(View.VISIBLE);
            mRefresh_rel.setVisibility(View.GONE);
        } else {
            mStop_rel.setVisibility(View.GONE);
            mRefresh_rel.setVisibility(View.VISIBLE);
        }
    }
    if (view != null && view.canGoForward()) {
        mForward.setAlpha(0.9f);
    }else{
        mForward.setAlpha(0.2f);
    }

    if (view != null && view.getUrl() != null) {
        (((MainActivity) MainActivity.getMainActivity())).onAmpPage(view.getUrl().contains("/amp/"));
    }

}
 
Example 7
Source File: LightningChromeClient.java    From Xndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceivedTitle(@Nullable WebView view, @Nullable String title) {
    if (title != null && !title.isEmpty()) {
        mLightningView.getTitleInfo().setTitle(title);
    } else {
        mLightningView.getTitleInfo().setTitle(mActivity.getString(R.string.untitled));
    }
    mUIController.tabChanged(mLightningView);
    if (view != null && view.getUrl() != null) {
        mUIController.updateHistory(title, view.getUrl());
    }
}
 
Example 8
Source File: WebViewCacheInterceptor.java    From CacheWebView with MIT License 5 votes vote down vote up
@Override
public void loadUrl(WebView webView, String url, Map<String, String> additionalHttpHeaders) {
    if (!isValidUrl(url)) {
        return;
    }
    webView.loadUrl(url, additionalHttpHeaders);
    mReferer = webView.getUrl();
    mOrigin = NetUtils.getOriginUrl(mReferer);
    mUserAgent = webView.getSettings().getUserAgentString();
}
 
Example 9
Source File: WebViewCacheInterceptor.java    From CacheWebView with MIT License 5 votes vote down vote up
@Override
public void loadUrl(WebView webView, String url) {
    if (!isValidUrl(url)) {
        return;
    }
    webView.loadUrl(url);
    mReferer = webView.getUrl();
    mOrigin = NetUtils.getOriginUrl(mReferer);
    mUserAgent = webView.getSettings().getUserAgentString();
}
 
Example 10
Source File: FocusWebViewClient.java    From firefox-echo-show with Mozilla Public License 2.0 5 votes vote down vote up
@Override
    public void onPageFinished(WebView view, final String url) {
        SslCertificate certificate = view.getCertificate();

        if (!TextUtils.isEmpty(restoredUrl)) {
            if (restoredUrl.equals(url) && certificate == null) {
                // We just restored the previous state. Let's re-use the certificate we restored.
                // The reason for that is that WebView doesn't restore the certificate itself.
                // Without restoring the certificate manually we'd lose the certificate when
                // switching tabs or restoring a previous session for other reasons.
                certificate = restoredCertificate;
            } else {
                // The URL has changed since we restored the last state. Let's just clear all
                // restored data because we do not need it anymore.
                restoredUrl = null;
                restoredCertificate = null;
            }
        }

        if (callback != null) {
            callback.onPageFinished(certificate != null);
            // The URL which is supplied in onPageFinished() could be fake (see #301), but webview's
            // URL is always correct _except_ for error pages
            final String viewURL = view.getUrl();
            if (!UrlUtils.isInternalErrorURL(viewURL) && viewURL != null) {
                callback.onURLChanged(viewURL);
            }
        }
        super.onPageFinished(view, url);

//        evaluateJavascript(view,
//                "(function() {" +
//
//                CLEAR_VISITED_CSS +
//
//                "})();");
    }
 
Example 11
Source File: BrowserWebChromeClient.java    From Beedio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onReceivedTitle(WebView view, String title) {
    super.onReceivedTitle(view, title);
    VisitedPage vp = new VisitedPage();
    vp.title = title;
    vp.link = view.getUrl();
    new HistorySQLite(context).addPageToHistory(vp);
}
 
Example 12
Source File: VenvyWebView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getUrl() {
    if (mAgentWeb == null || mAgentWeb.getWebCreator() == null) {
        return null;
    }
    WebView webView = mAgentWeb.getWebCreator().getWebView();
    return webView != null ? webView.getUrl() : null;
}
 
Example 13
Source File: GameWebView.java    From kcanotify_h5-master with GNU General Public License v3.0 5 votes vote down vote up
private void detectLoginAndFill(WebView view, SharedPreferences prefs) {
    if (view.getUrl() != null && view.getUrl().contains(hostNameOoi.substring(0, hostNameOoi.length() - 3))) {
        boolean isAutoUser = prefs.getBoolean("ooi_auto_user", false);
        if (isAutoUser) {
            String userName = prefs.getString("dmm_user", "");
            String pwd = prefs.getString("dmm_pwd", "");
            view.loadUrl("javascript:$(\"#login_id\").val(\"" + userName + "\");$(\"#password\").val(\"" + pwd + "\");");
            view.loadUrl("javascript:document.getElementById(\"mode3\").checked = true;");
        }
    }
    // For DMM
    if(view.getUrl() != null && view.getUrl().startsWith("https://www.dmm.com/my/-/login/=")){
        new Handler().postDelayed(new Runnable(){
            public void run() {
                Set<Map.Entry<String, String>> dmmCookieMapSet = gameActivity.dmmCookieMap.entrySet();
                for (Map.Entry<String, String> dmmCookieMapEntry : dmmCookieMapSet) {
                    view.evaluateJavascript("javascript:document.cookie = '" + dmmCookieMapEntry.getKey() + "';", new ValueCallback<String>() {
                        @Override
                        public void onReceiveValue(String value) {
                            Log.i("KCVA", value);
                        }
                    });
                }
            }
        }, 5000);
    }
}
 
Example 14
Source File: ReactWebViewManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
@ReactProp(name = "source")
public void setSource(WebView view, @Nullable ReadableMap source) {
  if (source != null) {
    if (source.hasKey("html")) {
      String html = source.getString("html");
      if (source.hasKey("baseUrl")) {
        view.loadDataWithBaseURL(
          source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null);
      } else {
        view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
      }
      return;
    }
    if (source.hasKey("uri")) {
      String url = source.getString("uri");
      String previousUrl = view.getUrl();
      if (previousUrl != null && previousUrl.equals(url)) {
        return;
      }
      if (source.hasKey("method")) {
        String method = source.getString("method");
        if (method.equals(HTTP_METHOD_POST)) {
          byte[] postData = null;
          if (source.hasKey("body")) {
            String body = source.getString("body");
            try {
              postData = body.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
              postData = body.getBytes();
            }
          }
          if (postData == null) {
            postData = new byte[0];
          }
          view.postUrl(url, postData);
          return;
        }
      }
      HashMap<String, String> headerMap = new HashMap<>();
      if (source.hasKey("headers")) {
        ReadableMap headers = source.getMap("headers");
        ReadableMapKeySetIterator iter = headers.keySetIterator();
        while (iter.hasNextKey()) {
          String key = iter.nextKey();
          if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
            if (view.getSettings() != null) {
              view.getSettings().setUserAgentString(headers.getString(key));
            }
          } else {
            headerMap.put(key, headers.getString(key));
          }
        }
      }
      view.loadUrl(url, headerMap);
      return;
    }
  }
  view.loadUrl(BLANK_URL);
}
 
Example 15
Source File: Web3WebviewManager.java    From react-native-web3-webview with MIT License 4 votes vote down vote up
@ReactProp(name = "source")
public void setSource(WebView view, @NonNull ReadableMap source) {
    if (source != null) {
        if (source.hasKey("html")) {
            String html = source.getString("html");
            if (source.hasKey("baseUrl")) {
                view.loadDataWithBaseURL(
                        source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null);
            } else {
                view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
            }
            return;
        }
        if (source.hasKey("uri")) {
            String url = source.getString("uri");
            String previousUrl = view.getUrl();
            if (source.hasKey("method")) {
                String method = source.getString("method");
                if (method.equals(HTTP_METHOD_POST)) {
                    byte[] postData = null;
                    if (source.hasKey("body")) {
                        String body = source.getString("body");
                        try {
                            postData = body.getBytes("UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            postData = body.getBytes();
                        }
                    }
                    if (postData == null) {
                        postData = new byte[0];
                    }
                    view.postUrl(url, postData);
                    return;
                }
            }
            HashMap<String, String> headerMap = new HashMap<>();
            if (source.hasKey("headers")) {
                ReadableMap headers = source.getMap("headers");
                ReadableMapKeySetIterator iter = headers.keySetIterator();
                while (iter.hasNextKey()) {
                    String key = iter.nextKey();
                    if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
                        if (view.getSettings() != null) {
                            view.getSettings().setUserAgentString(headers.getString(key));
                        }
                    } else {
                        headerMap.put(key, headers.getString(key));
                    }
                }
            }
            view.loadUrl(url, headerMap);
            return;
        }
    }
    view.loadUrl(BLANK_URL);
}
 
Example 16
Source File: FocusWebViewClient.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void onPageFinished(WebView view, final String url) {
    SslCertificate certificate = view.getCertificate();
    shouldReadURL = true;

    if (!TextUtils.isEmpty(restoredUrl)) {
        if (restoredUrl.equals(url) && certificate == null) {
            // We just restored the previous state. Let's re-use the certificate we restored.
            // The reason for that is that WebView doesn't restore the certificate itself.
            // Without restoring the certificate manually we'd lose the certificate when
            // switching tabs or restoring a previous session for other reasons.
            certificate = restoredCertificate;
        } else {
            // The URL has changed since we restored the last state. Let's just clear all
            // restored data because we do not need it anymore.
            restoredUrl = null;
            restoredCertificate = null;
        }
    }

    if (callback != null) {
        // The page is secure when the url is a localized content or when the certificate isn't null
        final boolean isSecure = certificate != null || UrlUtils.isLocalizedContent(view.getUrl());

        callback.onPageFinished(isSecure);

        String host = null;
        try {
            host = new URI(url).getHost();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        callback.onSecurityChanged(isSecure, host, (certificate != null) ? certificate.getIssuedBy().getOName() : null);
        // The URL which is supplied in onPageFinished() could be fake (see #301), but webview's
        // URL is always correct _except_ for error pages
        final String viewURL = view.getUrl();
        if (!UrlUtils.isInternalErrorURL(viewURL) && viewURL != null) {
            callback.onURLChanged(viewURL);
        }
    }
    super.onPageFinished(view, url);

    view.evaluateJavascript(
            "(function() {" +

            CLEAR_VISITED_CSS +

            "})();",

            null);
}
 
Example 17
Source File: MainFragment.java    From chromium-webview-samples with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get reference of WebView from layout/activity_main.xml
    mWebView = (WebView) rootView.findViewById(R.id.fragment_main_webview);

    setUpWebViewDefaults(mWebView);

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        // Restore the previous URL and history stack
        mWebView.restoreState(savedInstanceState);
    }

    mWebView.setWebChromeClient(new WebChromeClient() {
        public boolean onShowFileChooser(
                WebView webView, ValueCallback<Uri[]> filePathCallback,
                WebChromeClient.FileChooserParams fileChooserParams) {
            if(mFilePathCallback != null) {
                mFilePathCallback.onReceiveValue(null);
            }
            mFilePathCallback = filePathCallback;

            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                // Create the File where the photo should go
                File photoFile = null;
                try {
                    photoFile = createImageFile();
                    takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
                } catch (IOException ex) {
                    // Error occurred while creating the File
                    Log.e(TAG, "Unable to create Image File", ex);
                }

                // Continue only if the File was successfully created
                if (photoFile != null) {
                    mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                            Uri.fromFile(photoFile));
                } else {
                    takePictureIntent = null;
                }
            }

            Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
            contentSelectionIntent.setType("image/*");

            Intent[] intentArray;
            if(takePictureIntent != null) {
                intentArray = new Intent[]{takePictureIntent};
            } else {
                intentArray = new Intent[0];
            }

            Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
            chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
            chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

            startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);

            return true;
        }
    });

    // Load the local index.html file
    if(mWebView.getUrl() == null) {
        mWebView.loadUrl("file:///android_asset/www/index.html");
    }

    return rootView;
}