PortFrowarding in Chrome…answer to connecting device browser to machine’s server + Inspecting WebView

This is what i was looking for, but sadly wasn’t available till now :
Came across it while looking thru the Google IO videos : http://www.youtube.com/watch?v=2OgAetgR_ok
Time : 3.25.
Looks straightforward…will try it out soon and update here….
Other Tools (mentioned in the video) :
responsive inspector extension
Inspecting WebView
jsconsole.com
Basically see :  cloud based testing
And Automated Testing : http://goo.gl/5WsMy
Google Analytics Live Feed….for ur app upto the level of Device Breakpoints and Page Load Speeds.

Advertisements

Android WebView

WebView (inApp and Chrome both) Using Native Android Code and Phonegap

TO OPEN URL IN APP ITSELF :

package com.mkyong.android;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;

public class WebViewActivity extends Activity {

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);

String url =”http://www.google.com”;
WebView wv=(WebView) findViewById(R.id.webView1);
wv.getSettings().setJavaScriptEnabled(true);
   wv.getSettings().setPluginState(PluginState.ON);
   wv.getSettings().setAllowFileAccess(true);
wv.loadUrl(url);

//String customHtml = “<html><body><h1>Hello, WebView</h1><body><script>var ref = window.open(‘http://www.google.com&#8217;, ‘_system’, ‘location=yes’);</script></body></html>”;
//webView.loadData(customHtml, “text/html”, “UTF-8”);

}

}

FANCY WAY

public class WebViewActivity extends Activity {

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);

WebSettings mWebSettings;

        WebView mWebView = (WebView)findViewById(R.id.webView1);
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
        mWebView.setBackgroundColor(Color.TRANSPARENT);
        mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_INSET);

        mWebView.loadUrl(“https://www.google.co.in/&#8221;);
        mWebView.setWebViewClient(new MyWebViewClient());
}


}

package com.mkyong.android;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MyWebViewClient extends WebViewClient { 
    @Override 
    //show the web page in webview but not in web browser
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
        view.loadUrl (url); 
        return true;
    } 
}

TO OPEN URL IN BROWSER : 

package com.mkyong.android;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;

public class WebViewActivity extends Activity {

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);

webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(“http://www.google.com&#8221;);

//String customHtml = “<html><body><h1>Hello, WebView</h1><body><script>var ref = window.open(‘http://www.google.com&#8217;, ‘_system’, ‘location=yes’);</script></body></html>”;
//webView.loadData(customHtml, “text/html”, “UTF-8”);

}

}

FINALLY GOT THE PHONEGAP THING WORK TOO …THE ISSUE WA THAT I WAS ONLY RUNNING THE PHONEGAP ANDROID EXAMPLE  FROM  : …\phonegap-2.7.0\phonegap-2.7.0\lib\android\example

BUT ACTUALLY  I ALSO HAD TO REPLACE THE INDEX.HTML CODE WITH FULL EG. CODE FROM http://docs.phonegap.com/en/2.7.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser.
But SADLY that also opens inAppBrowser….
OPEN FILE SYSTEM HTML

webView.loadUrl(“file:///android_asset/www/index.html”);

In both cases this is always opening in the App, but i need it to open in Browser…

Resources :

http://developer.android.com/guide/webapps/webview.html#AddingWebView

NEXT STEP :

1. how to load html from file system in browser using android code
2. how to package web apps into android

ANOTHER IDEAL WAY OF DOING THIS IN THIS CIRCUMSTANCE IS TO DEVELOP A HMTL5 WEB APP THAT USES OFFLINE STORAGE..NOW WHEN THE APP IS LAUNCHED, THE APP WILL TRY TO HIT THE URL AND IF IT IS OFFLINE, IT WILL LOAD THE LOCAL HTML FILE (STORED IN THE BROWSER LOCAL STORAGE)……

THAT REMINDS ME THAT I ALREADY HAVE A HOSTED APP FOR USERMEDIA : http://tkhemani.github.io/getusermedia_tk (IF THIS HAS ANY ISSUES USE  http://simpl.info/getusermedia/ )

WELL, ALL I HAD TO DO WAS OPEN IT USING ABOVE CODE :)))))))

FINAL STEP WOULD BE TO CACHE THIS PAGE LOCALLY AND I’M DONE….



Looked into the local storage feature and tried to see some egs.

Next step : understand and use   http://appcache-demo.s3-website-us-east-1.amazonaws.com/localstorage-cache/