I have an app that finishes everything OK on a Samsung Galaxy S7, version 7.0, API 24. But when I try it on a Huawei CAM-L03, version 6.0, API 23, it does not work.
I basically have a class like this:
public class Sender extends AsyncTask {...}
That has the methods onPreExecute , doInBackground and onPostExecute , to communicate with a php file occupying the internet. When I run it on the Samsung Galaxy S7, and perform a Toast.makeText , to display text per screen in each method, everything works fine and correctly, so here's no problem. But when I run it on the Huawei CAM-L03 , it only shows me on-screen texts of the methods onPreExecute and onPostExecute , but never enters do doInBackground , and I do not know why.
To call the class I do this:
Sender s = new Sender (MainActivity.this, Total_Route);
s.execute ();
I do not know if it's the version, the SDK, or something else. Any help is appreciated.
Here is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.pruebainsp"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:design:26.1.0'
implementation files('libs/PhotoUtil.jar')
implementation files('libs/GenAsync.1.2.jar')
}
EL Toast.makeText is not really the problem .. I only added it to be able to visualize the behavior of the code, to check which methods went in and which did not. The real problem is that DoInBackground does not do anything or never comes in to do something.
Here is the code for the Sender class. With the Samsung Galaxy S7 enter if (MainActivity.ResponseWeb! = Null) , but in the Huawei CAM-L03 the ResponseWeb is always null, then every time I get the message Toast.makeText (c, "Error: response" + MainActivity.ResponseWeb, Toast.LENGTH_SHORT) .show (); , and you will never perform private String send () for the connection, since doInBackground does not work here (ONLY ON THE HUAWEI PHONE).
IR A EDIT 1
EDIT 1:
Update the code to contain some logs, here it is:
public class Sender extends AsyncTask<Void,Void,String> {
Context c;
String urlAddress;
ProgressDialog pd;
String fileTodosUsers = "TodosUsuarios";
private static final String TAG = Sender.class.getSimpleName();
/*
1.OUR CONSTRUCTOR
2.RECEIVE CONTEXT,URL ADDRESS AND EDITTEXTS FROM OUR MAINACTIVITY
*/
public Sender(Context c, String urlAddress) {
this.c = c;
this.urlAddress = urlAddress;
//Log.v(TAG, "Mensaje 2");
}
/*
1.SHOW PROGRESS DIALOG WHILE DOWNLOADING DATA
*/
@Override
protected void onPreExecute() {
Log.i(TAG, "OnPre");
super.onPreExecute();
pd=new ProgressDialog(c);
pd.setTitle("En Proceso");
pd.setMessage("Procesando datos...Espere por favor");
pd.show();
}
/*
1.WHERE WE SEND DATA TO NETWORK
2.RETURNS FOR US A STRING
*/
@Override
protected String doInBackground(Void... params) {
Log.i(TAG, "doInBack");
return this.send();
}
/*
1. CALLED WHEN JOB IS OVER
2. WE DISMISS OUR PD
3.RECEIVE A STRING FROM DOINBACKGROUND
*/
@Override
protected void onPostExecute(String response) {
Log.i(TAG, "onPost");
super.onPostExecute(response);
MainActivity.ResponseWeb = response;
if (MainActivity.ResponseWeb != null) {
//...
//HERE CODE DO SOME STUFF
//...
}
else {
Toast.makeText(c, "Error: response " + MainActivity.ResponseWeb , Toast.LENGTH_SHORT).show();
}
pd.dismiss();
}
/*
SEND DATA OVER THE NETWORK
RECEIVE AND RETURN A RESPONSE
*/
private String send()
{
Log.i(TAG, "On Send 1");
//CONNECT
HttpURLConnection con=Connector.connect(urlAddress);
Log.i(TAG, "On Send 2");
if(con==null)
{
Log.i(TAG, "On Send 3");
return null;
}
try
{
Log.i(TAG, "On Send 4");
OutputStream os=con.getOutputStream();
Log.i(TAG, "On Send 5");
//WRITE
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(os,"UTF-8"));
Log.i(TAG, "On Send 6");
bw.flush();
Log.i(TAG, "On Send 7");
//RELEASE RES
bw.close();
Log.i(TAG, "On Send 8");
os.close();
Log.i(TAG, "On Send 9");
//HAS IT BEEN SUCCESSFUL?
int responseCode=con.getResponseCode();
Log.i(TAG, "On Send 10");
Log.i(TAG, "responseCode = " + responseCode);
if(responseCode==con.HTTP_OK)
{
Log.i(TAG, "On Send 11");
//GET EXACT RESPONSE
BufferedReader br=new BufferedReader(new InputStreamReader(con.getInputStream()));
Log.i(TAG, "On Send 12");
StringBuffer response=new StringBuffer();
Log.i(TAG, "On Send 13");
String line;
Log.i(TAG, "On Send 14");
//READ LINE BY LINE
while ((line=br.readLine()) != null)
{
Log.i(TAG, "On Send 15");
response.append(line);
}
//RELEASE RES
Log.i(TAG, "On Send 16");
br.close();
Log.i(TAG, "On Send 17");
return response.toString();
}else
{
Log.i(TAG, "On Send 18");
}
} catch (IOException e) {
Log.i(TAG, "On Send 19");
e.printStackTrace();
}
Log.i(TAG, "On Send 20");
return null;
}
And here is Logcat's:
04-04 15:34:01.402 20341-20341/com.example.pruebainsp I/Sender: OnPre
04-04 15:34:01.445 20341-20550/com.example.pruebainsp I/Sender: doInBack
04-04 15:34:01.445 20341-20550/com.example.pruebainsp I/Sender: On Send 1
04-04 15:34:01.445 20341-20550/com.example.pruebainsp I/Sender: On Send 2
04-04 15:34:01.446 20341-20550/com.example.pruebainsp I/Sender: On Send 4
04-04 15:34:01.561 20341-20550/com.example.pruebainsp I/Sender: On Send 5
04-04 15:34:01.562 20341-20550/com.example.pruebainsp I/Sender: On Send 6
04-04 15:34:01.562 20341-20550/com.example.pruebainsp I/Sender: On Send 7
04-04 15:34:01.562 20341-20550/com.example.pruebainsp I/Sender: On Send 8
04-04 15:34:01.562 20341-20550/com.example.pruebainsp I/Sender: On Send 9
04-04 15:34:01.700 20341-20550/com.example.pruebainsp I/Sender: On Send 10
04-04 15:53:57.934 27226-27436/com.example.pruebainsp I/Sender: responseCode = 403
04-04 15:34:01.700 20341-20550/com.example.pruebainsp I/Sender: On Send 18
04-04 15:34:01.700 20341-20550/com.example.pruebainsp I/Sender: On Send 20
04-04 15:34:02.214 20341-20341/com.example.pruebainsp I/Sender: onPost