I want to upload images (using asyncTask),but if my internet is down,i want to send a broadcast intent and upload images automatically when internet is connected next time. I have successfully uploaded images when internet is active, I saw many examples but none of them helped me.
i have a class UploadImages which extends AsyncTask
I made broadcast receiver class like this
public class MyBroadcastReceiver extends BroadcastReceiver {
ConnectivityManager connec;
@Override
public void onReceive(Context context, Intent intent) {
connec = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connec != null && (connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED) ||(connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED))
{
Intent intent1 = new Intent(context, UploadIntentService.class);
intent1.putExtra("", "index.html");
context.startService(intent);
}
}
}
Here is my UploadIntentService class
public UploadIntentService() {
super("uploadIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
new UploadImageToBucket().execute("");
Intent broadcastIntent = new Intent();
broadcastIntent.setAction("com.alg.imgSave.MyBroadcastReceiver");
broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
broadcastIntent.putExtra("RESPONSE_STRING", "1");
broadcastIntent.putExtra("RESPONSE_MESSAGE", "Uploaded");
sendBroadcast(broadcastIntent);
}
But this is not working