标签: android-websettings

单击URL将打开默认浏览器

我已经加载了一个外部URL WebView.现在我需要的是当用户点击加载页面上的链接时,它必须像普通浏览器一样工作并打开相同的链接WebView.但它打开默认浏览器并在那里加载页面?

我启用了JavaScript.但它仍然无法正常工作.我忘记了什么吗?

url android android-webview android-websettings

206
推荐指数
6
解决办法
13万
查看次数

Websettings.SetAppCacheEnabled 已弃用,该使用什么替代?

在尝试将较旧的 Android 应用程序带入现代世界的过程中,我遇到了以下已弃用的声明:

websettings.setAppCacheEnabled(false)
Run Code Online (Sandbox Code Playgroud)

现代 Androidx 替代方案是什么?

android android-websettings

36
推荐指数
2
解决办法
2万
查看次数

Android - 以编程方式检查互联网连接并显示对话框(如果未连接)

我正在进行一个现场项目.当用户点击应用程序时 出现欢迎屏幕(该屏幕上有一个webview).如果互联网没有连接,那么应用程序崩溃.基本上,我的问题是以编程方式检查移动设备是否连接到互联网.如果没有,则不要将数据从webservice提取到webview中,并显示一个对话框,显示"检查你的网络连接"

在做研究时我发现了很多东西,我试图实现它.但是,它不满足我的要求

我的代码是,

public boolean isOnline() {
    ConnectivityManager cm =
        (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    }
    else
    {
        Description.setVisibility(View.INVISIBLE);
        new AlertDialog.Builder(WelcomePage.this)
        .setTitle(getResources().getString(R.string.app_name))
        .setMessage(
                getResources().getString(
                        R.string.internet_error))
        .setPositiveButton("OK", null).show();
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

我打电话这一功能doInBackground()AsyncTask

请帮忙!

android android-webview android-internet android-websettings

22
推荐指数
5
解决办法
5万
查看次数

Webview无法接受cookie

我正在创建一个基于WebView的Android应用程序,使用户可以登录移动运营商.当我运行应用程序时,WebView会打开网站,但我收到一条消息,表明WebView不允许使用cookie.我尝试过各种我在这里找到的代码,但都没有.谁能帮我?这是我正在使用的代码:

//in oncreate
final CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(this);
final CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeSessionCookie();
String[] cookies = getCookie("https://myaccount.ee.co.uk/login-dispatch/?fa=register");
for (String cookie : cookies) {
    cookieManager.setCookie("https://myaccount.ee.co.uk/login-dispatch/?fa=register", cookie);
}
cookieSyncManager.sync();
webView.loadUrl("https://myaccount.ee.co.uk/login-dispatch/?fa=register");
Run Code Online (Sandbox Code Playgroud)

和getCookies方法:

public String[] getCookie(String siteName) {
     CookieManager cookieManager = CookieManager.getInstance();
     String cookies = cookieManager.getCookie(siteName);
     String[] cookiesArray = cookies.split(";");
     return cookiesArray;
}
Run Code Online (Sandbox Code Playgroud)

cookies android android-webview android-websettings android-cookiemanager

13
推荐指数
2
解决办法
1万
查看次数

如何使用适合屏幕在所有设备中显示Webview内部的WebPage的某些部分

我想在WebView中显示WebPage.到目前为止,这很好.

但我有WebPage(如下所示),我想要它的某些部分.我的意思是只有左上角应该在所有设备中都适合屏幕模式.

我在过去两三天就解决了这个问题.

我想要的是: 我希望显示网页的左上角以显示内部Webview,无论Stratergy可能是缩放或任何其他选项,但它应该适合所有设备的屏幕.

还有一件事我不能改变网页的源代码,因为它是固定的. 我必须通过代码本身进行管理.

在此输入图像描述

我尝试了什么: 我已经引用Stackoverflow链接但没有运气.

这是我的代码.:

            WebView wv;
        wv = (WebView) findViewById(R.id.webview_MyPoops);
        wv.getSettings().setJavaScriptEnabled(true);

        // wv.setInitialScale(185);

        // wv.setInitialScale(30);
        String URL = "MY_LINK";

        wv.loadUrl(URL);

        WebSettings webSettings = wv.getSettings();
        webSettings.setSavePassword(false);
        webSettings.setSaveFormData(false);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setUseWideViewPort(true);
Run Code Online (Sandbox Code Playgroud)

我正在获取设备中显示的完整网页.

它在我的LG设备(分辨率为480*800)中运行良好,但在大型设备或像Galaxy Tab2这样的标签中,我得到的是左上角的非常小的图像,所有其他屏幕区域只是WebPage的背景.

以下是运行上述代码后Galaxy Tab2的屏幕截图. 在此输入图像描述 请你有任何我缺乏的建议.提前致谢.

android webpage webview android-webview android-websettings

12
推荐指数
1
解决办法
2588
查看次数

如何在Android webview中完全禁用所有输入的软键盘

我正在使用phonegap为Android开发一个Web应用程序,因为我将在HTML中拥有自己的键盘,我需要禁用android的系统键盘,防止它在用户点击任何文本输入字段时出现.我不想使用只读输入字段,或者onblur()因为我想将光标放在文本字段中,所以用户可以在输入输入时移动光标位置.

所以,我要彻底禁用默认的Android键盘,我尝试添加android:windowSoftInputMode="stateAlwaysHidden"manifest.xml但这不起作用.

我也尝试使用这里的javascript界面,但Android 2.3.x上有一个javascript-java桥崩溃问题.(链接问题).所以我现在还没有一个好的解决方案.请帮忙.

提前感谢您的帮助.

javascript android android-webview android-websettings cordova

11
推荐指数
1
解决办法
5978
查看次数

Android WebView - 滚动条不填充layout_height

我有一个包含大量文本内容的WebView.我正在使用以下WebView设置:

    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);
    settings.setSupportZoom(false);
    settings.setBuiltInZoomControls(false);
    webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webview.setScrollbarFadingEnabled(false);
Run Code Online (Sandbox Code Playgroud)

Html视口设置为:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
Run Code Online (Sandbox Code Playgroud)

问题是滚动条在布局​​之外,如下所示:

我的Android布局是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <LinearLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />


    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android webview android-webview android-browser android-websettings

7
推荐指数
1
解决办法
296
查看次数

Log <GATE-M> DEV_ACTION_COMPLETED </ GATE-M>似乎延迟了在Android上的执行

我最近注意到我的应用程序偶尔有LAG.而LAG我的意思是它可能需要40秒,取决于我使用Wifi还是移动数据......

我加载页面URL,然后加载js执行:

    webView = (WebView) view.findViewById(R.id.WebView);

    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            logDebug("Loading URL: " + url);
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return WrappingClass.this.shouldOverrideUrlLoading(view, url);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        logInfo("loading JavaScript to webview.");
        webView.loadUrl("full-js-here");

        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            logError("error code:" + errorCode);
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    });

    WebSettings webSettings …
Run Code Online (Sandbox Code Playgroud)

android android-webview android-browser webviewclient android-websettings

6
推荐指数
1
解决办法
2775
查看次数

即使使用@SuppressWarnings("弃用"),Android Studio也会被弃用警告

在Android Studio中,我们在构建期间收到了已弃用的警告.此代码位于Activity的onCreate(Bundle)中

String databasePath = webView.getContext().getDir("databases", Context.MODE_PRIVATE).getPath();
webSettings.setDatabaseEnabled(true);
webSettings.setDatabasePath(databasePath);
Run Code Online (Sandbox Code Playgroud)

该方法具有这些注释

@SuppressLint("SetJavaScriptEnabled")
@SuppressWarnings("deprecation")
@TargetApi(19)
@Override
public void onCreate(Bundle savedInstanceState) {
Run Code Online (Sandbox Code Playgroud)

我知道setDatabasePath已被弃用,但我们需要这个以实现向后兼容性.

我以为这会隐藏警告.当我们执行编译任务时,我会看到一条消息

.../app/src/main/java/com /.../ WebframeActivity.java警告:(106,15)[弃用] WebSettings中的setDatabasePath(String)已被弃用

我认为@SuppressWarnings注释不会将此报告为警告.我能做什么?这是一个错误还是我忽略了我的错误?

java android android-websettings android-studio android-gradle-plugin

6
推荐指数
0
解决办法
4771
查看次数

Phonegap/Cordova App在Jelly Bean中断 - Access-Control-Allow-Origin和setAllowUniversalAccessFromFileURLs

我一直在用Cordova(aka Phonegap)为Android开发*已经有一年多的时间了,我正在尝试让我的应用程序可以在Jelly Bean中运行,但是我收到以下错误:

XMLHttpRequest cannot load http://127.0.0.1:40582/[somerandomstring]. Origin null is not allowed by Access-Control-Allow-Origin. at null:1
Run Code Online (Sandbox Code Playgroud)

(以及请求使用localhost或file://的任何后续ajax的类似错误)为了测试,我在Access-Control-Allow-Origin部分中授予对config.xml中所有内容的访问权限

<access origin="*"/>
<access origin="http://127.0.0.1*"/>
Run Code Online (Sandbox Code Playgroud)

在我的研究中,我发现这个错误与Google在Android Jelly Bean中所做的设置更改有关.以下是我发现的内容:来自:https://git-wip-us.apache.org/repos/asf?p = entubator-cordova-android.git;a=commitdiff;h=07439ff9

- 这是来自org.apache.cordova.CordovaWebView

// Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
// while we do this
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
    Level16Apis.enableUniversalAccess(settings);
Run Code Online (Sandbox Code Playgroud)

- 这也来自org.apache.cordova.CordovaWebView

// Wrapping these functions in their own class prevents warnings in adb like:
// VFY: unable to resolve virtual …
Run Code Online (Sandbox Code Playgroud)

java android android-websettings cordova

4
推荐指数
1
解决办法
1万
查看次数

如何在Android中的webView中加载img标签?

我想在Android webview中加载以下HTML代码.

<!DOCTYPE html>
<html>
<body style = "text-align:center">

<img src="http://XXXXXXXX.com/books_snaps/UR335/1.jpg" alt="pageNo" 

height="100%" width="100%"> 

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

http://XXXXXXXX.com/books_snaps/UR335/1.jpg图像链接在哪里.我想在<img>上面的HTML标签中加载此图片.如何在Android的webview中嵌入HTML代码?

html android webview android-webview android-websettings

2
推荐指数
1
解决办法
7007
查看次数

在Android WebView中禁用电子邮件,数字检测

我正在开发一个带phonegap + sencha touch2 + android的应用程序.我有一个面板显示包含电子邮件的各种内容,一些文本形式的数字.因为它是一个WebView,当我点击数字,并且默认的MailCompose活动开始,当我点击数字拨号器活动开始.如何禁止这种情况发生.在为WebView加载url或web设置之前,是否有一些我在android端缺少的配置.或者来自Phonegap的东西,因为当我看到log cat它显示以下行 -

DroidGap.startActivityForResult(intent,-1)

android-intent android-webview android-websettings sencha-touch-2 cordova

0
推荐指数
1
解决办法
4619
查看次数