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

Asked

Viewed 1,102 times

2

I would like to create an application that requires constant data update, fast maintenance and development in a very short time, the application has no requirements other than to display information to the user.

I believe that the best solution would be an app that "navigates" on a web page, whose will take the role of the application displaying the information, as most Firefoxos apps do, however I did not find any specific tutorial, I only found to run the local application (on mobile) and request server data.

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

Obs: the app will be only for Android

2 answers

2

What you can do (and I’ve already done) is create an app that 'calls' the site. The code would be more or less 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’ve helped!

2


If the app will only be for Android, there is no reason to use Phonegap, because one of the premises is that, with the same code you can create app for various platforms.

You can do it in Pure Java, it will be simple to maintain, 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 down:

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 archive

Webviewactivity.java

Enter 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 website Android Webview example you will find more complete and complex examples and can improve your application.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.