Template Android app that displays a webpage
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

This task is to provide a template Android app, with instructions how to run and test it in a Linux development environment. The app should simply display an existing webpage. The app should open up the device's browser in order to display the webpage but should display the website inside the app itself. As I understand, this is possible using webview in Android, e.g:

{
WebSettings webSettings = mWebView.getSettings();
mWebView.getSettings().setSupportZoom(true);
mWebView.getSettings().setBuiltInZoomControls(true);
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://m.domainname.com/");
}

If the template depends on some particular development environment, then instructions how to run the template inside that environment should be provided.

awarded to keyfour

Crowdsource coding tasks.

2 Solutions


pre-dev qs are:
1. Which platforms and versions will you support?
2. What about offline support?
3. What form factors will you consider?

@source https://www.addthis.com/blog/2014/10/27/7-things-to-consider-when-making-ios-and-android-apps-with-cordova-or-phonegap/

  1. Android only (as stated in title)
  2. No offline support, i.e. no caching of webpages or local version. All pages should exclusive be pulled from a URL I put into the template. Setting of cookies should be allowed.
  3. Phone and tablets. I should add that the webpage already adjusts itself to form factors. So, no additional formatting of html/css code is necessary. As stated, the template should simply display the webpage in the app AS-IS.
greipes almost 3 years ago
Oh, I saw that 33 days ago: https://github.com/appfeel/admob-phonegap-build-demo
nope almost 3 years ago
Winning solution

You can use WebView with WebViewClient based class.

Fragment with example WebView:

public class WebViewFragment extends Fragment {

private final String defaultURL = "https://google.com";
private boolean isJavaScriptEnabled = true;
private boolean isLoadImagesAuto = true;


//Public constructor, need to FragmentManager
public WebViewFragment() {}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {


    //Inflate with resource file without attachment to root
    View view = inflater.inflate(R.layout.fragment_web_view, container, false);

    WebView webView = (WebView) view.findViewById(R.id.webview);

    //We need to have client to use as browser
    webView.setWebViewClient(new MyBrowser());
    webView.getSettings().setLoadsImagesAutomatically(isJavaScriptEnabled);
    webView.getSettings().setJavaScriptEnabled(isLoadImagesAuto);

    //Load default URL
    webView.loadUrl(defaultURL);

    return view;
}

private class MyBrowser extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}

}

Full example application project for Android Studio on github

Thank you! Just what I was after :-)
greipes almost 3 years ago
View Timeline