You need a server.
Apache servers are fine.
The easiest way (and a little bit dirty) is to make a login in your server for whatever the App is about.
Then in Android Studio you can use a Webview and load your server.
You need to know that it usually takes time to load.
If you are planning to do an app with an everyday connection, is better to look at Todd's answer, but if you only need some data, you will be OK working with Webviews.
Here is the code:
MainActivity.java
public class MainActivity extends AppCompatActivity {
WebView mWebView; //your webview
final String url ="http://www.yourwebpage.com"; // string with your webpage url
ProgressDialog mProgress; //progress dialog that appears if your connection is not good (its an extra)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
getSupportActionBar().hide();
mWebView = (WebView) findViewById(R.id.webView); //your webview
WebSettings ajustes = mWebView.getSettings(); //your websettings (i am spanish so i called it "ajustes")
ajustes.setJavaScriptEnabled(true); //enable javascript in your webview
ajustes.setBuiltInZoomControls(true);
ajustes.setSupportZoom(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.setWebViewClient(new MyWebClient());
mWebView.loadUrl(url); // here you call your url string that you made before
mProgress = ProgressDialog.show(this, "Loading...", "Wait please...."); // progress dialog text
mWebView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) { // in this fuction you deal with connection error so you show a toast that tells you that tere is not connection
Toast.makeText(main_activity.this, "THERE IS NOT CONNECTION.TRY AGAIN LATER", Toast.LENGTH_LONG).show();
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) { //when your page finishes loading, your progressdialog will disappear
if (mProgress.isShowing()) {
mProgress.dismiss();
}
}
});
// set url for webview to load
mWebView.loadUrl(url);
}
private class MyWebClient extends WebViewClient {
//AlertDialog.Builder alert = new AlertDialog.Builder(web.this);
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webView"
android:layout_gravity="center_horizontal" />
</LinearLayout>
So that was all the code.
If you need more aske me.
Adiós!!!