Eclipse Android App Zoom In Code WebView - android

I'm very new to developing android apps. I've edited this app I found, which was open source and have got it working to a good extent. There's some code that isn't being used at all (Like the preferences menu) but I haven't removed that as I simply don't want to mess it up. Anyway, when I view the website it's zoomed in.. I've researched the problem and found a few ways to fix it, but none have worked. The app files can be downloaded at this link: http://www.megafileupload.com/en/file/504860/App-zip.html
Thanks for any help!

Now, here's where the answer comes in.
You get the settings for your webview before you instantiate it. You need something like:
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard); // do this first
WebView webView = (WebView) findViewById(R.id.yourwebviewid); // either this or
either the above to tie the Java object to an xml object
or create a view and add it to some parent
View parent = (View)findViewById(R.id.yourparent_layout_for_webview); // this
WebView webView = new WebView();
parent.add(webView);
webView.getSettings().setBuiltInZoomControls(true);

Related

Android DatePicker is so slow in WebView

Below is the WebView code, which shows the webpage at here. Everything works fine. The date picker is so slow, everything else works fine. It takes like 4-5 seconds to select a date. Any alternatives?
public class click extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.click);
WebView webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.exceptnothing.com/appointment.html");
webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
}
}
I tried adding android:hardwareAccelerated="true" in that activity, same effect still.
I'm a beginner, so simpler code will be appreciated. Thanks in advance :)
try to checkout android DatePickerDialog. Its native and fast way to pick a date on android. Also, using webview in android applications is a bad practice to build a well formed user interfaces, it's realy decreases the application performance, look, and user feel. Native android vidgets are always best to do the work. This tutorial will help you if you decide to build your ui as views layout http://www.tutorialspoint.com/android/android_datepicker_control.htm

Android twitter connection/authentication intent bad formed?

I've been trying to connect to twitter through android for a while.
I'm currently using this api: http://kenai.com/projects/twitterapime/forums/forum/topics/13327-Twitter-API-ME-1-8-Now-with-OAuth-support
I used their exemple with my keys and everything connects without problem. So no problem with configuration.
But in my project which has exactly the same code I can't make it work.
I believe its related with the creation of a new Intent (also this is where the eclipse is point the error)
Im trying to use a custom layout but I don't know what do I need to change to make this specific Twitter layout to work. On main activity I have a button with this:
public void onClick(View v)
{
startActivity(new Intent(this,Twitter.class));
}
on twitter class
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this.webView = (WebView) findViewById(R.id.webView1);
WebView myWebView = new WebView(this);
setContentView(myWebView);
authenticate();
}
private void authenticate()
{
WebViewOAuthDialogWrapper page = new WebViewOAuthDialogWrapper(webView);
page.setConsumerKey(CONSUMER_KEY);
page.setConsumerSecret(CONSUMER_SECRET);
page.setCallbackUrl(CALLBACK_URL);
page.setOAuthListener(this);
page.login();
}
what requirements/adjustments are needed to make/change to the Twitter activity?
I believe I need to change something in the intent-filter but I don't even understand the work of intents. I've been only making easy layouts.
Note that I also gave internet permissions already.
Looks like i was making 2 mistakes.
First i was trying to use "webView" variable in WebViewOAuthDialogWrapper instead
"myWebView" so it wasn't initialized...
Second looks like i forgot to put the order of which the external libraries were loaded....
So be sure to put external libraries on top in eclipse project.
Lost about 2 days with these problems... oh well

How to automate clicking a link inside a WebView

Ok, guys. I know it sounds weird but what I want to achieve is when i run the app. The webview first load the link and after I enter all the details, it must automatically click a button inside the webview. Is there any possible way to do this?? I have tried with loading different links in order to open the new window.
for example,
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ourBrow = (WebView) findViewById(R.id.wvBrowser);
// cancel the web intent that default in android setting
ourBrow.setWebViewClient(new WebViewClient());
url = (TextView) findViewById(R.id.tvSC);
// webView settings
ourBrow.getSettings().setJavaScriptEnabled(true);
ourBrow.getSettings().setLoadWithOverviewMode(true);
ourBrow.getSettings().setUseWideViewPort(true);
Button SCode = (Button) findViewById(R.id.btSCode);
loadUrl("http://www.google.com.au");
this part works well, but what I want is when the length inside the search bar is equal to 4, the "search" button will automatically press
thanks so much for the help!!!
You could perhaps do this by executing some awkward javascript in the webview.
To just issue the click you could probably do something like
ourBrow.loadUrl("javascript:getElementById('button_id').click()");
Since you need to wait for the search bar to have a lenght of 4 you will probably want to register a listener on the field in javascript and issue the click there. I can't tell you the best way to do this, but you will probably need to set an eventlistener for 'change' or set onKeyUp or something similar and see if the field is of length >= 4 then issue the click. You could nest all of this in the javascript row.
Set it after the page has loaded, that is. Set a WebViewClient on the webview and load the javascript in the onPageFinished(WebView view, String url) callback or something similar.

How to make a web app for android?

I’ve been making android apps for like 4-5 days now. So i’m wondering if you know how I can make a web app? I have been looking through many tutorials, but none shows directly how I can make an app that displays the content from a website, and that I can decide what I want and don’t want to display. So I really just want to customize a website into an app and make my own layout. I know how the WebView and WebContent works and all that stuff, but I don’t know how I can do what I described here.
So what do I need to learn and know to make an app like that?
You can do it by fill your xml layout with EdidText for the url and Buttons for Go, back, forward and so on, finally you need webview in this xml layout.
for the java code you can check the below sample.
public class SimpleBrowser extends Activity implements OnClickListener {
WebView myBrowser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simplebrowser);
//here the code for initialize and set yourwebView Settings.
myBrowser= (WebView) findViewById(R.id.wvBrowser);
//the below line to enable javascript if you want that
myBrowser.getSettings().setJavaScriptEnabled(true);
//here another settings could be enabled for you your webview
myBrowser.getSettings().setLoadWithOverviewMode(true);
myBrowser.getSettings().setUseWideViewPort(true);
try {
//here the default web page
ourBrow.loadUrl("http://www.google.com");
}catch (Exception e){
e.printStackTrace();
}
}
}
and for sure you need to implements your buttons using onClicklistener to be suitable for your idea.
https://www.youtube.com/watch?v=lkadcYQ6SuY&index=89&list=PL2F07DBCDCC01493A
https://www.youtube.com/watch?v=PQ94MmEg0Qw&index=90&list=PL2F07DBCDCC01493A

how to run local web application in android webview

can anybody tell how to run the local webapplication using android webview
I want to run my own webpages in android using web view
Thanks
I'm guessing you want something like this:
private WebView mWebView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourLayoutWithAWebView);
mWebView = (WebView)findViewById(R.id.yourWebViewIdFromTheLayout);
mWebView.getSettings().setJavaScriptEnabled(true); // Enable JavaScript
mWebView.loadData(yourHtmlData, "text/html", "utf-8");
}
Hopefully, that at least points you in the right direction.
Also, I'd recommend reading the documentation on the WebView, it's pretty thorough.
Just run your application on the emulator, as you normally do (and be sure to have your computer connected to internet).

Categories

Resources