Issue
I load html from assets, and it runs properly, but the javascript file seems doesn`t run. I put alert(1) there to test, rebuild my app and nothing happens. In the same time javascript runs from the web, if I connect to the site with the same files(index.html, fun.js). So the web page(html) is running, but javascript(from file, that linked via tag) is not running.
MainAcivity.java
WebView myWebView = findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
if( activeNetworkInfo != null && activeNetworkInfo.isConnected())
{myWebView.loadUrl("http://load_real_site.com");}
else
{myWebView.loadUrl("file:///android_asset/index.html");}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
What's wrong?
Solution
The problem was in javascript file. Seems, the problem was in declaring an array as var a=[];, although it worked in web. Making var a=[0]; solved the problem and javascript ran.
Answered By - bcubeu26dncs
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.