1
I’m developing an app that customers and drivers log in, I wanted when my app runs in the background and when a customer sends a message, the driver receives a notification, all the data is in an online bank and the system and login, registration etc is already ok, so, how do I know if I got the message in the background and show that I got it to the driver.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_buscar_motorista);
showProgress(true);
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if(networkInfo != null && networkInfo.isConnected()) {
url = ip;
parametros = "mensagem=buscar";
new SolicitaDados().execute(url);
} else {
Toast.makeText(getApplicationContext(), "Nenhuma conexão foi detectada", Toast.LENGTH_LONG).show();
}
}
private void showProgress(final boolean show) {
// On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
// for very easy animations. If available, use these APIs to fade-in
// the progress spinner.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
login.setVisibility(show ? View.VISIBLE : View.GONE);
login.animate().setDuration(shortAnimTime).alpha(
show ? 1 : 0).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
login.setVisibility(show ? View.VISIBLE : View.GONE);
}
});
} else {
// The ViewPropertyAnimator APIs are not available, so simply show
// and hide the relevant UI components.
login.setVisibility(show ? View.VISIBLE : View.GONE);
login.setVisibility(show ? View.GONE : View.VISIBLE);
}
}
private class SolicitaDados extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
return Conexao.postDados(urls[0], parametros);
}
@Override
protected void onPostExecute(String resultado) {
mensagem= resultado;
}
In the above code in the oncreate it makes the request and in onPostExecute it picks the result and puts everything in the string
How you’re getting this message in the app?
– Valdeir Psr
I put when the driver opens the app he makes the request and receives a mailing list if it exists in the bank, but I wanted him to make this request from time to time in the background
– user98257
Okay, I put the code part
– user98257