Yes, There is. Few points before the solution
- Make your service STICKY, with a foreground notification as it would be necessary to work on or after
Build.VERSION_CODES.O
- This sticky service, you should start on every boot, via
BOOT_COMPLETED
intent action and starting this foreground service from receiver.
- Yes, Now it is always there, Now you can always go for checking your connection
- You can use
google-volley
for making connections and even you can communicate using it.
- There is no good documentation on it, But i like it much, as it works flawlessly once added the dependency successfully.
- Adding this dependency will take time as i said no good documentation..
For communication :
StringRequest stringRequest = new StringRequest(Request.Method.POST, "https://oniony-leg.000webhostapp.com/user_validation.php",
new Response.Listener<String>()
{
@Override
public void onResponse(String response)
{
serverKeyResponse = response;
// get full table entries from below toast and writedb LICENSETABLE
//Toast.makeText(getActivity(),response,Toast.LENGTH_LONG).show();
showKeyResponse();
// Log.d("XXXXXX XXXXX", "\n SUCCESS : "+serverKeyResponse);
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
serverKeyResponse = error.toString();
// show below toast in alert dialog and it happens on slow internet try again after few minutes
// on ok exit app
// Toast.makeText(getActivity(),error.toString(),Toast.LENGTH_LONG).show();
showKeyResponse();
//Log.d("YYYYYY YYYYYY", "\n FAILURE : "+serverKeyResponse);
}
})
{
@Override
protected Map<String,String> getParams()
{
Map<String,String> params = new HashMap<String, String>();
params.put("INPUT",LicenseKey.getText().toString());
params.put("USER", MainActivity.deviceid);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
requestQueue.add(stringRequest);
You just have to reply ECHO "SUCCESS"
from server using a php ( or whatever server side language you like ). In response check for SUCCESS
presence, any any other cases.., Use other KEYWORDS YOU LIKE. You can handle Server response errors too
. Even you can communicate from android in request - response handshake. But you have to implement few handshake on your own.
I Hope, It helps...