use of android.net.ConnectivityManager in project k-9 by k9mail.
the class RemoteStore method getInstance.
/**
* Get an instance of a remote mail store.
*/
public static synchronized Store getInstance(Context context, StoreConfig storeConfig) throws MessagingException {
String uri = storeConfig.getStoreUri();
if (uri.startsWith("local")) {
throw new RuntimeException("Asked to get non-local Store object but given LocalStore URI");
}
Store store = sStores.get(uri);
if (store == null) {
if (uri.startsWith("imap")) {
OAuth2TokenProvider oAuth2TokenProvider = null;
store = new ImapStore(storeConfig, new DefaultTrustedSocketFactory(context), (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), oAuth2TokenProvider);
} else if (uri.startsWith("pop3")) {
store = new Pop3Store(storeConfig, new DefaultTrustedSocketFactory(context));
} else if (uri.startsWith("webdav")) {
store = new WebDavStore(storeConfig, new WebDavHttpClient.WebDavHttpClientFactory());
}
if (store != null) {
sStores.put(uri, store);
}
}
if (store == null) {
throw new MessagingException("Unable to locate an applicable Store for " + uri);
}
return store;
}
use of android.net.ConnectivityManager in project Fairphone by Kwamecorp.
the class FairphoneUpdater method isWiFiEnabled.
private boolean isWiFiEnabled() {
ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
return isWifi;
}
use of android.net.ConnectivityManager in project remusic by aa112901.
the class NetworkUtils method isConnectInternet.
public static boolean isConnectInternet(final Context pContext) {
final ConnectivityManager conManager = (ConnectivityManager) pContext.getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo networkInfo = conManager.getActiveNetworkInfo();
if (networkInfo != null) {
return networkInfo.isAvailable();
}
return false;
}
use of android.net.ConnectivityManager in project storymaker by StoryMaker.
the class StorymakerDownloadManager method downloadFromLigerServer.
private void downloadFromLigerServer() {
String ligerUrl = indexItem.getExpansionFileUrl();
String ligerPath = StorymakerIndexManager.buildFilePath(indexItem, context);
String ligerObb = fileName;
Timber.d("DOWNLOADING " + ligerObb + " FROM " + ligerUrl + " TO " + ligerPath);
try {
URI expansionFileUri = null;
HttpGet request = null;
HttpResponse response = null;
File targetFolder = new File(ligerPath);
String nameFilter = "";
if (ligerObb.contains(indexItem.getExpansionFileVersion())) {
nameFilter = fileName.replace(indexItem.getExpansionFileVersion(), "*") + "*.tmp";
} else {
nameFilter = fileName + "*.tmp";
}
Timber.d("CLEANUP: DELETING " + nameFilter + " FROM " + targetFolder.getPath());
WildcardFileFilter oldFileFilter = new WildcardFileFilter(nameFilter);
for (File oldFile : FileUtils.listFiles(targetFolder, oldFileFilter, null)) {
Timber.d("CLEANUP: FOUND " + oldFile.getPath() + ", DELETING");
FileUtils.deleteQuietly(oldFile);
}
// additional cleanup of pre-name-change files
if (fileName.contains(scal.io.liger.Constants.MAIN)) {
nameFilter = fileName.replace(scal.io.liger.Constants.MAIN + ".", "").replace(indexItem.getExpansionFileVersion(), "*");
Timber.d("CLEANUP: DELETING OLD FILES " + nameFilter + " FROM " + targetFolder.getPath());
oldFileFilter = new WildcardFileFilter(nameFilter);
for (File oldFile : FileUtils.listFiles(targetFolder, oldFileFilter, null)) {
Timber.d("CLEANUP: FOUND OLD FILE " + oldFile.getPath() + ", DELETING");
FileUtils.deleteQuietly(oldFile);
}
}
File targetFile = new File(targetFolder, ligerObb + ".tmp");
// if there is no connectivity, do not queue item (no longer seems to pause if connection is unavailable)
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if ((ni != null) && (ni.isConnectedOrConnecting())) {
if (context instanceof Activity) {
// FIXME move to strings
Utils.toastOnUiThread((Activity) context, "Starting download of " + indexItem.getTitle() + ".", false);
}
// check preferences. will also need to check whether tor is active within method
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
boolean useTor = settings.getBoolean("pusetor", false);
boolean useManager = settings.getBoolean("pusedownloadmanager", false);
//if (checkTor(useTor, context)) {
if (useTor && useManager) {
Timber.e("ANDROID DOWNLOAD MANAGER IS NOT COMPATABLE WITH TOR");
if (context instanceof Activity) {
// FIXME move to strings
Utils.toastOnUiThread((Activity) context, "Check settings, can't use download manager and tor", true);
}
StorymakerQueueManager.checkQueueFinished(context, targetFile.getName());
} else if (useTor || !useManager) {
downloadWithTor(useTor, Uri.parse(ligerUrl + ligerObb), mAppTitle + " content download", ligerObb, targetFile);
} else {
downloadWithManager(Uri.parse(ligerUrl + ligerObb), mAppTitle + " content download", ligerObb, Uri.fromFile(targetFile));
}
} else {
Timber.d("NO CONNECTION, NOT QUEUEING DOWNLOAD: " + ligerUrl + ligerObb + " -> " + targetFile.getPath());
if (context instanceof Activity) {
// FIXME move to strings
Utils.toastOnUiThread((Activity) context, "Check settings, no connection, can't start download", true);
}
StorymakerQueueManager.checkQueueFinished(context, targetFile.getName());
}
} catch (Exception e) {
Timber.e(e, "DOWNLOAD ERROR: " + ligerUrl + ligerObb + " -> " + e.getMessage());
}
}
use of android.net.ConnectivityManager in project GT by Tencent.
the class DeviceUtils method setMobileDataStatus.
public static void setMobileDataStatus(boolean enable) {
ConnectivityManager conMgr = (ConnectivityManager) GTApp.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
Class<?> conMgrClass = null;
Field iConMgrField = null;
Object iConMgr = null;
Class<?> iConMgrClass = null;
Method setMobileDataEnableMethod = null;
try {
conMgrClass = Class.forName(conMgr.getClass().getName());
iConMgrField = conMgrClass.getDeclaredField("mService");
iConMgrField.setAccessible(true);
iConMgr = iConMgrField.get(conMgr);
iConMgrClass = Class.forName(iConMgr.getClass().getName());
setMobileDataEnableMethod = iConMgrClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
setMobileDataEnableMethod.setAccessible(true);
setMobileDataEnableMethod.invoke(iConMgr, enable);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
Aggregations