I'm developing an app that clients and drivers log, I wanted when my app was running in the background and when a customer sent a message, the driver received a notification, all the data is in an online bank and the system is login , registration etc is already ok, so how do I know if I received the message in the background and show that I received 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 oncreate it makes the request and in the onPostExecute it catches the result and puts everything in the string