when user connects to the internet it starts uploading pictures to the server.
Service invoke when broadcast receiver receive the internet connect event this starts uploading.
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
assert cm != null;
NetworkInfo info = cm.getActiveNetworkInfo();
if (info != null) {
if (info.isConnected()) {
Intent intentnew = new Intent(context, UploadService.class);
context.startService(intentnew);
}
}
void startUploading(final File file) {
Runnable runnable = new Runnable() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void run() {
uploadFile(file);
}
};
new Thread(runnable).start();
}