How to create an app on Phonegap using an online page?

2

I would like to create an application that needs constant data maintenance, fast maintenance and development in a very short time, the application has no requirements besides displaying information to the user.

I think the best solution would be an app that "browses" on a web page, which will assume the role of the application displaying the information, as most applications of FirefoxOS does, however I did not find any specific tutorial, run the local application (on mobile) and request data from the server.

How can I develop? is allowed on all versions of Android an IFRAME for example?

obs: the application will only be for Android

    
asked by anonymous 03.11.2015 / 06:01

2 answers

2

If the application is only for Android, you do not have to use Phonegap, since one of its premises is that with the same code you can create an app for various platforms.

You can do in Java Pure, it will be simple maintenance if you already have the site hosted on some server.

You will use the WebView component.

Create an android project normally and in the file

  

MainActivity.java

Put this code below:

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

    private Button button;

    public void onCreate(Bundle savedInstanceState) {
        final Context context = this;

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        button = (Button) findViewById(R.id.buttonUrl);

        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(context, WebViewActivity.class);
                startActivity(intent);
            }

        });

    }

}

In the file

  

WebViewActivity.java

Place this code:

import android.app.Activity;
import android.os.Bundle;
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");

        String customHtml = "<html><body><h1>Hello, WebView</h1></body></html>";
        webView.loadData(customHtml, "text/html", "UTF-8");

    }

}

On this site Android WebView example you will find more complete and complex examples and you can improve your application.

    
03.11.2015 / 12:44
2

What you can do (and I've already done) is create an app that 'calls' the site. The code would look something like this:

    <script type="text/javascript" charset="utf-8">
      var appd;
      document.addEventListener("deviceready", onDeviceReady, false);
      function onDeviceReady() {
      appd = window.open('http://seusite.com.br', '_blank', 'location=yes');
      }
   </script>

<body>


 <div class="app"></div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
</body>

This will open the page you want in the device browser.

I hope I have helped!

    
03.11.2015 / 12:25