Im trying to implement my web app / page inside android studio from my local files, ive followed the official documentation and made an webview button in xml, and declared :
<uses-permission android:name="android.permission.INTERNET" />
in the manifest file. My java activity code is below :
package samples.opencv.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview =(WebView)findViewById(R.id.webview);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
webview.loadUrl("file:///C:/Users/olive/OneDrive/Documents/ComputerScience/Project/Atom/index.html");
}
}
but i get the error on the emulator saying the webpage cannot be loaded as file is not found.
Put your web resources into the assets folder, usually under <project>/src/main/assets
, because emulator cannot see the file under your computer root ".../C:/Users/olive/OneDrive/Documents/ComputerScience/..."
then call:
webView.loadUrl("file:///android_asset/index.html");
Remember that in Android application, files can be read from 3 types of locations:
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.