I have a functional app in Android Studio that relies on connecting to a local database. In the following question How to connect my Android application to a database server? They give a pretty good general answer, but my question is a bit more specific.
I make my connection through the XAMPP control panel, for the connection through mysql. Following these youtube tutorials: Connect to a database in Android from 0 , it is explained how to make the connection locally, introducing the files inside the htdocs folder in the XAMPP installation directory. The tutorials then explain how to make a class in Android studio that connects to my local server by giving an ip address.
My htdocs folder, where I have the php files that I need for my connection. These files return JSON objects to me.
My question is the following:
Now that I want to connect not to a local server, but to an external server, is there any way to achieve this while maintaining the php file system that I have now?
The class that I use to, for example, connect to the Login file that allows me to make the first connection is the following:
package com.tigestion.guillermo.agendagui;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Guillermo on 04/10/2017.
*/
public class LoginRequest extends StringRequest{
private static final String LOGIN_REQUEST_URL =
"http://192.168.1.159/Login.php";
private Map<String, String> params;
public LoginRequest(String username, String password,
Response.Listener<String> listener){
super(Request.Method.POST, LOGIN_REQUEST_URL, listener, null);
params = new HashMap<>();
params.put("us_usuario", username);
params.put("us_clave", password);
}
@Override
public Map<String, String> getParams(){
return params;
}
}
Is there a way to change it so that instead of connecting to my local server, it connects to the external server?
(edited)
In my Gradle file I have the following line:
compile 'com.android.volley:volley:1.0.0'
And my manifest file contains the following:
<uses-permission android:name="android.permission.INTERNET" />
Do I need any more permissions apart from those?
In the following line of code you point to your server:
In your case you use the IP of your machine, but now you must point to your web server for example:
Now your files
PHP
where you have yourCRUD
must store them in your WebService, as well as your database. Note that some attributes may need to be changed, such as DB name, DB key, some WS require prepared statements for connections, etc. It will depend on your WS configuration.As now the use of the Internet will be essential in your app, I suggest you add validations for these cases.
In terms of permission, you should check that your "physical server" accepts remote connections, that your
PHP
are well done with prepared statements ( check documentation ) for greater security, etc.and for the part of Android Studio, you must give those of the Internet at least.
If you have doubts, I will gladly help you as much as possible...