WebView activity will use the Internet, so you must add the Internet usage permission in your AndroidManifest.xml file.
<uses-permission
android:name = "android.permission.INTERNET"/>
Then in your main Activity, define a WebView and associate it with your layout.
mWebView = (WebView) findViewById(R.id.web_view);
For a WebView you have a few choices about displaying contents. You can open a URL, you can create your HTML code inside your Activity and display it, you can open HTML files from your device's drive and also you can display other contents from your device's drive.
// Loading a URL
mWebView.loadUrl("http://www.androtips.com");
// Loading HTML code created in the Activity
String data = "<html><body><h2>Hello WebView</h2></body></html>";
String mimeType = "text/html";
String encoding = "utf-8";
mWebView.loadData(data , mimeType , encoding);
// Loading an HTML file or any content from sd card
String filePath = "
file:///data/data/com.webkitdemo/test.html";
mWebView.loadUrl(filePath);
Now you have a basic WebView to display your contents. The problem with this default WebView is, when you click to a link in the webpage, Android will attempt to open its default Browser. Of course we want to open any links from our WebView open in our own WebView. To do this, we must add this small inner-class to our Activity.
private class mWebViewClient extends WebViewClient {
/** Opens new links in the same WebView instead of opening it in Browser Application.
*
*/
@Override
public boolean shouldOverrideUrlLoading(WebView view , String url) {
view.loadUrl(url);
return true;
}
}
Another good feature to add to our activity is setting the behavior of the Back button of device. So that we can go back from a link we went from our WebView.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
Because we have small display sizes on mobile devices, we might need to add zoom controls to our WebView to enhance readability. In order to add zoom controls, you must add this controls into your onCreate method.
@Override
public void onCreate(Bundle savedInstanceState) {
...
...
// Zoom controls
FrameLayout mContentView = (FrameLayout) getWindow().getDecorView().findViewById(android.R.id.content);
final View zoom = this.mWebView.getZoomControls();
mContentView.addView(zoom, ZOOM_PARAMS);
zoom.setVisibility(View.GONE);
...
...
}
Your WebView is ready to use now. You can display any content in this WebView and integrate it into your Applications.
Enjoy!
I’ve been searching for some decent stuff on the subject and haven't had any luck up until this point, You just got a new biggest fan!.. download UC mini
ReplyDeleteBig data is a term that describes the large volume of data – both structured and unstructured – that inundates a business on a day-to-day basis. big data projects for students But it’s not the amount of data that’s important.Project Center in Chennai
DeleteSpring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Corporate TRaining Spring Framework the authors explore the idea of using Java in Big Data platforms.
Spring Training in Chennai
The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It 's really very nice and Useful post.Thanks Search Bar Firefox 57 Quantum addon
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteIt's really worth reading the blog post whcih has useful content. I have recently done CRS Info Solutions which is highly helpful to upgrade my career. What is the Salesforce course training fee in Chennai? Which is the best option from Salesforce Certification Training in Chennai? Who offers job oriented Salesforce training in Chennai? Find the best institute for project based Salesforce training in Chennai.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteReally wonderful and interesting blog, I enjoyed reading this post.
ReplyDeletewhat is seo content writing
german language to english
salesforce basics
star certification
free hacking books
Full-pay 9-6 machines are most typical in Nevada, however they are often present in Illinois, Indiana, Mississippi, Missouri -- indeed, nearly anywhere could be} competitors for players. Even in Nevada, some casinos offer the 8-5 pay desk, generally even alternating 9-6 and 8-5 pay tables on the similar financial institution of machines. Be sure to learn the pay desk earlier than sitting all the way down 우리카지노 to} play. If you are be} in an space with several of} casinos inside walking distance, do not settle for a pay desk that's under the usual for the area.
ReplyDeleteThe subtractive process of CNC machining provides multiple of} advantages for both prototyping and low-volume manufacturing parts. Work with a trusted U.S.-based producer and remove the risk of sending parts overseas. You can even call or e mail us at any time and we'll help with ordering parts, design feedback, materials suggestions, and answer any questions. CNC Waterjet – Water cutters use a high-pressure stream of water to cut via the steel, offering a excessive stage of accuracy and an excellent good} floor finish since there aren't any heat-effected edges. I bought this CNC mill for mildew making with aluminum and copper. You shouldn't beat Vacuum Storage Bags the worth for what this machine is able to doing for hobbyists.
ReplyDelete