Back to project page dCache-Cloud.
The source code is released under:
Copyright ? 2013, Michael Stapelberg and contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following ...
If you think the Android project dCache-Cloud listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package de.desy.dCacheCloud.BCReceiver; //w w w. j av a2s .c o m import java.util.ArrayList; import de.desy.dCacheCloud.DatabaseHelper; import de.desy.dCacheCloud.UploadService; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; import android.util.Log; public class NetworkReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.d("davsync", "network connectivity changed"); if (!ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) return; ConnectivityManager cs = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cs.getActiveNetworkInfo(); if (info == null || !info.isConnected()) { Log.d("davsync", "_NOT_ connected anymore, not doing anything."); return; } SharedPreferences preferences = context.getSharedPreferences("de.desy.dCacheCloud_preferences", Context.MODE_PRIVATE); boolean syncOnWifiOnly = preferences.getBoolean("auto_sync_on_wifi_only", true); if (syncOnWifiOnly && !(ConnectivityManager.TYPE_WIFI == info.getType())) { Log.d("davsync", "Not on WIFI, not doing anything."); return; } Log.d("davsync", "Checking whether pictures need to be synced"); // XXX: It doesnt really feel right to do this blockingly in a // BroadcastReceiver, but I was unable to find whether this is the right // way or whether there is a better one. DatabaseHelper helper = new DatabaseHelper(context); ArrayList<String> uris = helper.getQueuedUris(); for (String uri : uris) { Intent ulIntent = new Intent(context, UploadService.class); // evtl: mapintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ulIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(uri)); context.startService(ulIntent); } } }