simplest way to load android webview - android

what is the simplest way to load android webview?
I have already specified webview in the activity layout, how can i load a website on it while running the emulator. I have had many problems with resources not identified and the main_activity.out.xml files have been giving me troubles. A simple webview to load a webpage would be nice.
...
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />

You are getting main_activity.out.xml because you are trying to compile Xml files (main_activity.out.xml have the focus and you clicked run). In general if this error happens you have to
Delete the xxx.out.xml
Open any .java file in src/ by double click in the file so it has focus and the cursor is in there
Run your project and everything should be OK now
to load WebView you have to declare your webview component in your xml
<WebView
android:id="#+id/myWebView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
and then in your activity in onCreate() method call
// get reference to your view
WebView webview = (WebView)findViewById(R.id.myWebView);
// load your WebView content
webview.loadUrl("http://google.com/");

Simplest way?
Get access to WebView via
WebView webview = (WebView)findViewById(R.id.webView1);
webview.loadUrl("http://stackoverflow.com/");
Greets
Flo

main_activity.out.xml has been created maybe beacuse you pressed the run button on Eclipse while your main_activity.xml was opened. Eclipse tryed to compile your xml and not your application.
To do that right, try to select the reference of your application inside the project explorer on the left and then click the Run button.
In order to manage at best the webview in your android project, just read the documentation:
http://developer.android.com/guide/webapps/webview.html

Related

Create an app from responsive site that uses ajax calls that return both html and javascript - easiest way?

I'm looking for the easiest and most efficient way to create a mobile app from my website that is already fully responsive.
I have a page that contains 5 different ajax calls. Each ajax call returns both html and javascript which is created by a PHP script. All JavaScript that is is not user dependent is in a separate file. There is also a separate file for all css.
I think converting the code (using phonegap) will be very difficult because of the ajax calls. Preferably I would like to have an app that installs an icon on someone's phone and that just opens my website in a browser (without showing anything of that browser).
My question: What is the easiest way to create an app for android and ios?
Webview? If you are looking to build an app that just opens your webpage and does not show that its opened AOSP browser or any other browser for that matter then just use webview. It would open like any other activity in your app but the content (depending on how big you want the webview) will just be your site. I did a very similar thing in my android app and here is the code.
Java Class:
public class website extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_website);
String url = "http://www.YourWebsiteHere.co.uk";
WebView view = (WebView) this.findViewById(R.id.webViewSite);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(url);
}
XML File:
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webViewSite"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" /> </RelativeLayout>
http://developer.android.com/reference/android/webkit/WebView.html

webview does not show all content

I need to load url in webView - http://intor.club/files/comments.php?serial=56
I can not see in the webView that I see in the browser. Mobile browser works.
JavaScript is on. Help me! Thank you!
mWebView = (WebView) rootView.findViewById(R.id.webView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://intor.club/files/comments.php?serial=56");
First make sure you xml file you showing your webview like that
width fill parent and height also
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
don't forget your internet permission in AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
it should work know
i test it myself
when i comment javascript enable i got this
//wbeview.getSettings().setJavaScriptEnabled(true);
when i enable java Script i get this (there are no comment in this thread)
i see you want access comment , may be you not authorized to access it.
Things you should try :-
1- try connect your facebook or any other connection to this site and access this link again .
2- try connect to main Page it will work "http://intor.club/ "

android webview not showing html tabs properly

In my app , I am having a webview . In webview ,I am showing HTML content which is having tag , .I have 2 tabs in that which should switch on clicking on same place. But in webview they are coming one after the other.
In HTML file, I am calling method of Jquery file that method is not getting called . In browser its working fine. In iOS its working.
I am loading webview with base Url method only.
webView.loadDataWithBaseURL(pathToHtml, strLoad, "text/html","UTF-8", "");
These files are in assets . I am not sure that I am able to provide correct path for jquery files. So , I copied files to sdcard. There I am giving path. So path can not be the issue.
Please help me out . I tried many things but nothing worked. I am not getting what is the issue.
You can call a javascript function from webView.loadUrl("javascript:testFunction();"); to change the tabs insted of loading the page again. at the first load, you can use webView.loadUrl("file:///android_asset/index.html"); Befor using the jquery code, make sure that javascript enabled, set the webviewclient and webchromeclient for the webView.

Titanium webview.reload() not working correct

When I try to reload the titanium webview true webview.reload(), the view does not reload correctly. Instead if loading the page it gives me a page not found.
what i'm doing:
In Titanium i make use of webviews to display data. These webviews make use of HTML that is stored in the local filesystem that Titanium offers. The webview is called url is set by :
webview.setUrl( Ti.Filesystem.applicationDataDirectory.toString() + 'index.html');
This sets the proper url for the webview, it let's me see the correct html page. When I use webview.reload(), it seems lost... is there a way to reload the webview, or should i remove and then add the webview again?
Setting a URL for WebView the resource is usually loaded from the Resources folder.
So try to move all HTML files there (into Resources, same folder where app.js is located) and simply use.
webview.setUrl('index.html');
This has worked for me both on iOS and Android.
(There is an issue related to Android regarding WebView and setting its content by html property but this shouldn't matter here)

Android webview twitter link not opening

The link below is not opening in android webview .I am new to android. Someone help me to open this link in webview.
https://mobile.twitter.com/SCHOOLinSITES
I tried to open it in the following manner
XML
<WebView android:id="#+id/webView51"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
Activity
WebView w=(WebView)findViewById(R.id.webView51);
w.getSettings().setDomStorageEnabled(true);
w.getSettings().setJavaScriptEnabled(true);
w.loadUrl("https://mobile.twitter.com/SCHOOLinSITES");
Set a userAgent in your Webview.
webView.getSettings().setUserAgentString("Android");
webView.loadUrl("https://mobile.twitter.com/SCHOOLinSITES");

Categories

Resources