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?
Related
I am using HTML content (which is a gif image) to be viewed in a Webview. WEbview is successfully loaded the HTML content and the Gif image appeard. But, after some time the Emulator freezed and it stopped responses. Thanks in advance for any help.
public class ABC extends AppCompatActivity {
WebView webview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.abc);
webview=(WebView)findViewById(R.id.webview) ;
webview.loadUrl("file:///android_asset/hayder.html");
}
}
android manifest add this
<application
...
android:hardwareAccelerated="true"
...
>
I want to display a html file from a URL into a webview
If i run the app on a device running pre-lollipop (4.2)the html file is displayed as desired like below
But if i run the app on a device running lollipop (5.1)its showing unformatted text in webview like below
Why does this happen ?
mainactivity
public class MainActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String webViewurl = "http://files.parsetfss.com/f1c96efa-83e3-4dc3-8e0e-7c5b6dbbd7a2/tfss-7862469c-fb9d-4e9e-b914-779fd8415e13-main.html";
WebView wv = (WebView) findViewById(R.id.mainWebView);
wv.loadUrl(webViewurl);
}
}
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
I have a problem. I created some app, which should open my website, but when I run the app on my phone, its ask me in which browser I want to open it(Google Chrome...). But I want that website is open in app, not in browser... I'm working with Android Studio 1.1.0... Here is my code in MainActivity.java:
public class MainActivity extends ActionBarActivity {
private WebView MyWeb;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyWeb = (WebView) findViewById(R.id.WebView);
MyWeb.getSettings().setJavaScriptEnabled(true);
MyWeb.getSettings().setSaveFormData(true);
MyWeb.loadUrl("http://www.mywebsite.com");
} }
P.S. I changed the url to the fake one...
Add this line of code before your MyWeb.loadUrl
MyWeb.setWebViewClient(new WebViewClient());
This worked for me.!
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");
}
}