Html file not loading from assets folder - android

I am trying to load from asset folder. I tried following and googling around. But, my file doesn't load up. It says "Web page not available"
Here is my code:
HelpActivity.java
public class HelpActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
((WebView) findViewById(R.id.webView1))
.loadUrl("file///android_asset/help.html");
}
public void closeWindow(View v) {
finish();
}
}
help.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".HelpActivity" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</WebView>
</LinearLayout>
help.html
<html>
<body>
Hello world
</body>
</html>
Should i include any permissions in AndroidManifest?

You're missing a : from your file protocol:
file:///android_asset/help.html
^

WebView mWebVwRehat = (WebView) findViewById(R.id.webView1;
mWebVwRehat.setBackgroundColor(0); // to make webview transparent
mWebVwRehat.loadUrl("file:///android_asset/help.html");

((WebView) findViewById(R.id.webView1)).loadUrl("file:///android_asset/help.html");

Related

Problem: Loading Mapbox in Webview (Android Studio Project)

I have an html file in my website:
http://manizani.ir/hamyar_gas_php/map/map_app.html
I want to show it on my Android Application. I created an Activity and use a Webview to load above url. But nothing is loaded and it shows me just an empty activity.
I can load any other web pages successfully, but not about my url.
Please help me to solve it.
Thanks a lot
activity_map_web.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapWebActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:id="#+id/webview_intro"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</WebView>
</LinearLayout>
</RelativeLayout>
//////////////End of file//////////////////
MapWebActivity.java :
public class MapWebActivity extends AppCompatActivity {
WebView WV;
String url = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_web);
try {
WV = (WebView) findViewById(R.id.webview_intro);
WV.getSettings().setLoadsImagesAutomatically(true);
WV.getSettings().setJavaScriptEnabled(true);
WV.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
WV.getSettings().setBuiltInZoomControls(true);
WV.getSettings().setDomStorageEnabled(true);
WV.getSettings().setAppCacheEnabled(true);
WV.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
WV.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
WV.setWebViewClient(new WebViewClient());
url="http://manizani.ir/hamyar_gas_php/map/map_app.html";
WV.loadUrl(url);
} catch (Exception ex) {
Toast.makeText(this, ex.toString(), Toast.LENGTH_SHORT).show();
}
}
}
Mapbox use WebGL and may be is not support on your device.
webview log :
[INFO:CONSOLE(31)] "Error: Failed to initialize WebGL", source: https://api.mapbox.com/mapbox-gl-js/v2.2.0/mapbox-gl.js (31)
more at here

WebView is just loading white screen

I am trying to start a new activity with a WebView but when I try and load the activity, I am just brought to a white screen.
My Activity just has this as the code
public class TrainingVideos extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_training_videos);
WebView trainingWebview = (WebView) findViewById(R.id.web_trainingVideos);
trainingWebview.getSettings().setJavaScriptEnabled(true);
trainingWebview.loadUrl(url);
}
}
with my XML having
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/octtan"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
tools:context="com.octitle.ryann.octmobile.TrainingVideos">
<WebView
android:id="#+id/web_trainingVideos"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hardwareAccelerated="false" />
</FrameLayout>
And my manifest including
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
Try this
trainingWebview.getSettings().setJavaScriptEnabled(true);
trainingWebview.get settings().setLoadsImagesAutomatically(true);
trainingWebview.loadUrl(url);
Try to open the url in your app and not using your navigator
WebView trainingWebview = (WebView) findViewById(R.id.web_trainingVideos);
//New line to open the url in your app
trainingWebview.setWebViewClient(new WebViewClient());
trainingWebview.loadUrl(url);
trainingWebview.getSettings().setJavaScriptEnabled(true);
It turns out that it was an issue with self signed certificates contacting the server I was using.

How to load url of phonegap in native webview not in cordova webview?

I am trying to load url inside my custom webview
webview.xml-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none">
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ScrollView>
</RelativeLayout>
and here is my classfile
public class AppDev extends CordovaActivity implements WLInitWebFrameworkListener {
private WebView webview;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
WL.createInstance(this);
WL.getInstance().showSplashScreen(this);
WL.getInstance().initializeWebFramework(getApplicationContext(), this);
webview = (WebView)findViewById(R.id.webView);
}
public void onInitWebFrameworkComplete(WLInitWebFrameworkResult result){
if (result.getStatusCode() == WLInitWebFrameworkResult.SUCCESS) {
// super.loadUrl(WL.getInstance().getMainHtmlFilePath());//
webview.loadUrl(WL.getInstance().getMainHtmlFilePath());
} else {
handleWebFrameworkInitFailure(result);
}}
loading url in webview is producing following error-
com.worklight.common.Logger$UncaughtExceptionHandler
java.lang.NullPointerException
com.worklight.common.Logger$UncaughtExceptionHandler(com.AppDev.AppDev.onInitWebFrameworkCo mplete(AppDev.java:49)
is there anyway to load url in custom webview not in cordova?
Any Help :(
Did you try following the Integrating Server Generated Pages in Hybrid Applications training module and sample application?
The module explains how to bring up a webview and display an external website in it (and return back to the application's webview).

Android webview doesn't stream dropbox video

I am trying to stream a video stored on dropbox on android's webview but only a blank space is
displayed, my code is below :
activity_web_view.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/tview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/webView"
android:text="Description" >
</TextView>
</RelativeLayout>
public class WebViewA extends Activity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://www.dropbox.com/s/XXXX/video.mp4?dl=0?client_id=XXXX");
}
}
I have also tried the following Urls on webView.loadUrl(), but none
of them work, only a blank space appears :
"https://dl.dropbox.com/s/XXXX/video1.mp4?dl=0?client_id=XXXX"
"https://dl.dropbox.com/s/XXXX/video2.mp4?dl=1?client_id=XXXX"
"https://dl.dropboxusercontent.com/s/XXXX/video1.mp4"
"https://www.dropbox.com/s/XXXX/video1.mp4?dl=0"
if I try http://www.google.com it works, I have also seen some tutorials
with dropbox addresses that have an 'u' instead of an 's' like
"https://www.dropbox.com/u/..."
does WebView only works with dropbox urls with an 'u', if so how can I
get that type of address.

Getting errors while trying to run WebView application

I am creating an application in which I have to use webView and display a HTML file saved in application in assets folder. This is my mainActivity code.
public class MainActivity extends Activity {
WebView browser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
browser = (WebView)findViewById(R.id.wv1);
browser.loadUrl("file:///android_asset/test.htm");
WebSettings webSettings = browser.getSettings();
browser.getSettings().setJavaScriptEnabled(true);
setContentView(browser);
}
}
and this is my xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test Application"
android:gravity="center_horizontal">
</TextView>
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/wv1"
android:layout_marginTop="3dp">
</WebView>
whin I am trying to run this application , it goes crash..
can any one please help me to find out what is the mistake i am doing.
You cannot call setContentView(browser) because browser is already a child of another view -- the LinearLayout.
If you don't need the other views, just change the layout xml file and remove them, leaving only the WebView. Otherwise, remove the setContentView(browser) line.
You're using setContentView() twice and supplying the view that already has a parent. That is why it is giving you the error saying call removeView() on the child's parent first. So remove setContentView(browser).
Your code should look like this.
public class MainActivity extends Activity {
WebView browser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
browser = (WebView)findViewById(R.id.wv1);
browser.loadUrl("file:///android_asset/test.htm");
browser.getSettings().setJavaScriptEnabled(true);
}
}

Categories

Resources