my application that interacts with a sql server works correctly on my emulator and a HUAWEI tablet version 7.x, but it fails to connect to the server on a Samsung tablet version 10+ and cell phone version 10+. I think it's a permission.INTERNET error or another one if someone can help me.
here are my codes and the log
Manifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission-sdk-23 android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission-sdk-23 android:name="android.permission.ACCESS_NETWORK_STATE"/>
ApiClient
public class ApiClient {
public static final String BASE_URL = "http://XXX.XXX.XXX.XXX:XXXX/";
public static Retrofit retrofit = null;
public static Retrofit getRetrofitInstance() {
if (retrofit ==null){
return new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
ApiInterface
@FormUrlEncoded
@POST("register.php")
Call<Contact> registerContact(
@Field("FirstName") String firstname_,
@Field("LastName") String lastname_,
@Field("ContactAddress") String adresse_,
@Field("Mobile") String tel_,
@Field("BirthDate") String BirthDate_
);
Register method
private void GoRegister() {
String firstname_ = this.firstname.getText().toString().trim();
String lastname_ = this.lastname.getText().toString().trim();
String adresse_ = this.adress.getText().toString().trim();
String tel_ = this.tel.getText().toString().trim();
String BirthDate_= this.BirthDate.getText().toString().trim();
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Please Wait ...");
dialog.show();
apiInterface = ApiClient.getRetrofitInstance().create(ApiInterface.class);
Call<Contact> call = apiInterface.registerContact(firstname_, lastname_, adresse_, tel_, BirthDate_);
call.enqueue(new Callback<Contact>() {
private Call<Contact> call;
private Throwable t;
@Override
public void onResponse(@NonNull Call<Contact> call, @NonNull Response<Contact> response) {
if(response.isSuccessful())
{
alertSuccess("Enregistrement effectuée");
dialog.dismiss();
}else{
alertEnregistrementFailed("Une erreur est survenue lors de l'enregistrement, veuiller réesayez");
dialog.dismiss();
}
}
@Override
public void onFailure(@NonNull Call<Contact> call, @NonNull Throwable t) {
alertConnexion("Echec de connection aux serveur");
dialog.dismiss();
}
});
}