Loading local html file from asset folder into a webview - android

Trouble in loading local html file from asset into a webview. HTML page has javascript code, so I have used webview.setJavaScriptEnabled(true) to enable it. It loads the html page, but not all the widgets properly. Any suggestions...

public class ViewWeb extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
WebView wv;
wv = (WebView) findViewById(R.id.webView1);
wv.loadUrl("file:///android_asset/hello.html");
}
}

Related

Load files from Assets folder in webview

I have a webview in my android app, the html file which gets loaded is on a server, however I need to address some files from app's assets folder. I wanted to ask how can I address those files.
Thanks
public class ViewWeb extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
WebView wv;
wv = (WebView) findViewById(R.id.webView1);
wv.loadUrl("file:///android_asset/aboutcertified.html"); // now it will not fail here
}
}
And in general you can use
getAssets().open("filename.txt"))
To get filea from assets
On a side note:please put some code next time that you have triedget

loading division of webpage in android webview

My webpage is divided in various parts instead of loading full page, i want to load a part of that page div id = map_canvas.
Below code is giving me full page but i want only one part map_canvas
public class Jetbill extends Activity {
public WebView myWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.jetbill);
myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl("http://jetbill.biz/users/login.php");
}
}

web view is not loading local html file in android

I am integrating html in android.I have created a web view, But i am not able load local html page. Surprisingly web view is loading 'http:google.com' properly, not my local html file. I have tried almost all possible link of SO. The error message is'Web Page could not be loaded'
WebView view = (WebView) findViewById(R.id.webView1);
view.loadUrl("file:///assets/www/trialhtml.html");![enter image description here][1]
Create your HTML file and place it in the assets folder, then you need to add these lines to the onCreate method like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
webView.loadUrl("file:///android_asset/test.html");
setContentView(webView);
}
Here is the final result:
try below code :-
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String myURL = "file:///android_asset/index.html";
WebView view = (WebView) findViewById(R.id.webView1);
/*By default Javascript is turned off,
* it can be enabled by this line.
*/
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new WebViewClient());
view.loadUrl(myURL);
}
Check ur file exist or not and also you can clean the project, and rebuild it.
paste your .html file in assets folder of your project folder. and create an xml file in layout folder with the fol code
WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
add fol code in activity
setContentView(R.layout.my);
WebView mWebView = null;
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/www/trialhtml.html"); //new.html is html file na

load .swf file from sd card and play

I am new in android development.I am developing an app,that can load a file path of .swf file from sd card, then want to play in webView. I don't want to use html file from android_asset folder. here is my code.this code show blank page.In this case what should i do?
`public class FlashFile extends Activity{
String sdCardFilePath;
private WebView mWebView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flash_view);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Bundle gotBusket = getIntent().getExtras();
sdCardFilePath = gotBusket.getString("key");
mWebView = new WebView(this);
mWebView = (WebView)findViewById(R.id.webView1);
mWebView.getSettings().setPluginState(PluginState.ON);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.loadUrl("file://"+sdCardFilePath);
}`

Android prob to show pdf in webview

I am using android Webview to load a url to show a pdf file.
Here is my code:
public class TestProgectActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView mtWebView=new WebView(this);
setContentView(mtWebView);
mtWebView.getSettings().setJavaScriptEnabled(true);
mtWebView.loadUrl("https://docs.google.com/viewer?url=http://www.cbwe.gov.in/HTMLEditor1/pdf/sample.pdf");
}
}
It is working for the link "https://docs.google.com/viewer?url=http://www.cbwe.gov.in/HTMLEditor1/pdf/sample.pdf".
But it is not working for "https://docs.google.com/viewer?url=http://www.pancreaze.net/pdf/PANCREAZE.pdf". When I am firing this url through Webview it is showing HTML content in the WebView instead of the actual pdf file. Here is the screenshot.
What is problem in my code?

Categories

Resources