List of usage examples for android.content Context getApplicationContext
public abstract Context getApplicationContext();
From source file:com.DGSD.DGUtils.Http.BetterHttp.java
public static void setContext(Context context) { if (appContext != null) { return;//w w w . j a v a 2s.c o m } appContext = context.getApplicationContext(); appContext.registerReceiver(new ConnectionChangedBroadcastReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); }
From source file:com.example.mediastock.util.Utilities.java
/** * Returns the file containing the blob//from w w w . j a v a 2s . c om * * @param type the typeDir directory, where type can be music or video * @param context the context * @param path the path of the file * @return the file containing the blob */ public static File getFile(String type, Context context, final String path) { ContextWrapper cw = new ContextWrapper(context.getApplicationContext()); File dir = cw.getDir(type + "Dir", Context.MODE_PRIVATE); final File[] fileNames = dir.listFiles(); File target = null; for (File file : fileNames) { if (file.getName().equals(path)) target = file; } return target; }
From source file:Main.java
private static boolean confirmDownload(Context context, String stringUrl) { try {//from ww w.j ava 2s. c om URL url = new URL(stringUrl); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); long candidateDate = urlConnection.getLastModified(); final SharedPreferences prefsManager = PreferenceManager .getDefaultSharedPreferences(context.getApplicationContext()); final long savedDate = prefsManager.getLong(stringUrl, 0); urlConnection.disconnect(); if (candidateDate <= savedDate) { return false; } timeToConfirm = candidateDate; return true; } catch (Throwable localThrowable) { localThrowable.printStackTrace(); return false; } }
From source file:Main.java
public static void sendBroadcast(Context context, String filter, String bundleName, Bundle bundle) { if (context == null) { return;//from w ww . jav a2 s.c o m } Intent intent = new Intent(); intent.setAction(filter); intent.putExtra(bundleName, bundle); if (mLocalBroadcastManager == null) { getLocalBroadcastManager(context.getApplicationContext()); } mLocalBroadcastManager.sendBroadcast(intent); }
From source file:name.gumartinm.weather.information.widget.WidgetIntentService.java
public static void deleteWidgetCurrentData(final Context context, final int appWidgetId) { final PermanentStorage store = new PermanentStorage(context.getApplicationContext()); store.removeWidgetCurrentData(appWidgetId); }
From source file:com.example.mediastock.util.Utilities.java
/** * It loads a media file from the storage. * @param type the typeDir directory, where type can be music or video * @param context the context/*w w w .j a va 2s . c o m*/ * @param path the path to the media file * @return a FileInputStream object that contains the media file */ public static FileInputStream loadMediaFromInternalStorage(String type, Context context, final String path) { ContextWrapper cw = new ContextWrapper(context.getApplicationContext()); File dir = cw.getDir(type + "Dir", Context.MODE_PRIVATE); final File[] fileNames = dir.listFiles(); File target = null; for (File file : fileNames) { if (file.getName().equals(path)) target = file; } FileInputStream fis = null; try { fis = new FileInputStream(target); } catch (FileNotFoundException e) { e.printStackTrace(); } return fis; }
From source file:com.cryart.sabbathschool.util.SSCore.java
public static SSCore getInstance(Context ctx) { if (ssInstance == null) { ssInstance = new SSCore(ctx.getApplicationContext()); }/*ww w. j av a2s. c o m*/ return ssInstance; }
From source file:Main.java
public static void sendBroadcast(Context context, String filter, String name, String value, String name1, String value1) {//w ww . j av a2s . c om Intent intent = new Intent(); intent.putExtra(name, value); intent.putExtra(name1, value1); intent.setAction(filter); if (mLocalBroadcastManager == null) { getLocalBroadcastManager(context.getApplicationContext()); } mLocalBroadcastManager.sendBroadcast(intent); }
From source file:com.cerema.cloud2.lib.common.accounts.AccountUtils.java
public static void saveClient(OwnCloudClient client, Account savedAccount, Context context) { // Account Manager AccountManager ac = AccountManager.get(context.getApplicationContext()); if (client != null) { String cookiesString = client.getCookiesString(); if (!"".equals(cookiesString)) { ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString); // Log_OC.d(TAG, "Saving Cookies: "+ cookiesString ); }/*from w ww .jav a2s. com*/ } }
From source file:Main.java
public static boolean isUpdateAvailable(Context paramContext, String paramString) { try {//from w w w . j ava 2 s .c om HttpURLConnection localHttpURLConnection = (HttpURLConnection) new URL(paramString).openConnection(); long l1 = localHttpURLConnection.getHeaderFieldDate("Last-Modified", System.currentTimeMillis()); localHttpURLConnection.disconnect(); long l2 = PreferenceManager.getDefaultSharedPreferences(paramContext.getApplicationContext()) .getLong(paramString, 0L); boolean toReturn = l1 > l2; return toReturn; } catch (Throwable localThrowable) { localThrowable.printStackTrace(); } return false; }