0

I know that this question is ask many times in stackoverflow, but their solution is didnt work for me. Thats why I am asking this question.

Now the question is that I am developing an app by android webview, now this app is working perfect in older version of android version but didnt working in latest android version i.e. 9

I tried many things from other solution like

webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);

added this code in onCreate method but didnt work.

Another I try is add the @xml/network-security-config file but this also didnt work.

Here is my network-security-config code

<?xml version ="1.0" encoding ="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain>onlineawaz.in</domain>
    </domain-config>
</network-security-config>

public class MainActivity extends AppCompatActivity {
    WebView webView;
    ProgressBar bar;
    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webView = (WebView) findViewById(R.id.webView2);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        bar =(ProgressBar) findViewById(R.id.progressBar2);
        webView.loadUrl("http://onlineawaz.in/");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new myWebClient());
    }

    public class myWebClient extends WebViewClient{
        //page event
    }
}
karan
  • 482
  • 1
  • 8
  • 30

1 Answers1

0

Try adding below code in the AndroidManifest.xml under application tag

android:usesCleartextTraffic="true"
tools:ignore="UnusedAttribute"

First-line will allow you to use HTTP URLs(Not recommended in Pie). The second line is used to ignore the warning for SDK less than 23.

Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60
  • it is complusory to take ssl for the url link for the latest android app? – karan Aug 19 '19 at 04:00
  • Yes. See [official documentation](https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic). `When the attribute is set to "false", platform components (for example, HTTP and FTP stacks, DownloadManager, and MediaPlayer) will refuse the app's requests to use cleartext traffic. Third-party libraries are strongly encouraged to honor this setting as well.` – Rahul Khurana Aug 19 '19 at 04:02
  • 1
    Awsome Rahul. Thank You Brother. :) – karan Aug 19 '19 at 04:04