ERR_CLEARTEXT_NOT_PERMITTED

时间:2019-09-12 15:47:40

标签: android internet-connection

我用android studio制作了一个android应用。 Internet,网络状态,WiFi状态有3个权限。我创建一个签名的apk文件。但是在安装应用程序后,当我尝试进入此应用程序时,它显示ERR_CLEARTEXT_NOT_PERMITTED

我在其他设备上尝试过。

这是我的android清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androapp.****">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" 
/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/**_logoo"
    android:label="@string/app_name"
    android:roundIcon="@drawable/**_logoo"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:testOnly="false">
    <activity android:name="com.androapp.pciu.MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

这是我的Java代码:

package com.androapp.***;
import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity  {
   private WebView myWebView;
   Toolbar toolbar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if(!isConnected(MainActivity.this)) 
buildDialog(MainActivity.this).show();
    else {

    }

    toolbar = (Toolbar) findViewById(R.id.ttoolbar);
    setSupportActionBar(toolbar);


    myWebView = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    myWebView.loadUrl("*************");
    myWebView.setWebViewClient(new WebViewClient());
}

public boolean isConnected(Context context) {

    ConnectivityManager cm = (ConnectivityManager) 
context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netinfo = cm.getActiveNetworkInfo();

    if (netinfo != null && netinfo.isConnectedOrConnecting()) {
        android.net.NetworkInfo wifi = 
cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        android.net.NetworkInfo mobile = 
cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

        if((mobile != null && mobile.isConnectedOrConnecting()) || (wifi 
!= null && wifi.isConnectedOrConnecting())) return true;
    else return false;
    } else
    return false;
}

public AlertDialog.Builder buildDialog(Context c) {

    AlertDialog.Builder builder = new AlertDialog.Builder(c);
    builder.setTitle("No Internet Connection");
    builder.setMessage("Please make sure your device connected to the 
Internet.");

    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() 
{

        @Override
        public void onClick(DialogInterface dialog, int which) {

            finish();
        }
    });

    return builder;
}
@Override
public void onBackPressed() {
    if(myWebView.canGoBack()){
        myWebView.goBack();
    } else {
        super.onBackPressed();
    }
    }
}

Screenshot

0 个答案:

没有答案