We are beginning with Android. We want to programmatically send files when internet is available (by email). We guess the best way to program it is to send the files to a queue if there isn't internet. When internet is detected, the files will begin to be uploaded one by one. We guess the code should be like the following:
A background service continually checks if there is internet:
public class EducarCabezoService extends Service{
@Override
public void onCreate() {
super.onCreate();
IntentFilter filter = new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
ciReceiver = new checkInternetReceiver();
registerReceiver(ciReceiver, filter);
The background service uses a BroadcastReceiver for that purpose:
public class checkInternetReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent uqofIntent = new Intent(context, UploadQueueOfFilesService.class);
context.startService(uqofIntent);
We didn't find how to put files in a queue (maybe it is not the normal procedure). We can use the method isOnline() from here:
public class MainActivity extends Activity {
public uploadFile (){
if (!isOnline()){
// TODO Send files to queue?
We neither know how to upload those files from that queue:
public class UploadQueueOfFilesService extends Service{
@Override
public void onCreate() {
// TODO Start uploading files