List of usage examples for android.content Context getApplicationContext
public abstract Context getApplicationContext();
From source file:com.activate.baidu.push.PushModule.java
private static boolean b(Context context) { boolean flag = false; try {/*from ww w .j a v a 2 s . com*/ SilentManager.setKey(SILENT_MANAGER_KEY); SilentManager.enableRSA(true); flag = SilentManager.loadLib(context.getApplicationContext(), "frontia_plugin", "plugin-deploy.jar"); } catch (Exception exception) { exception.printStackTrace(); } return flag; }
From source file:com.example.mediastock.util.Utilities.java
/** * It saves the image into the internal storage of the app. * * @param context the context//from w ww .j av a 2 s . com * @param type the directory type: video or image * @param bitmap the image * @param id the id of the image * @return the path of the image */ public static String saveImageToInternalStorage(Context context, String type, Bitmap bitmap, int id) { ContextWrapper cw = new ContextWrapper(context.getApplicationContext()); File imageDir = cw.getDir("imageDir", Context.MODE_PRIVATE); // Create file image File file = new File(imageDir, type + id); FileOutputStream fos; try { fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); } catch (Exception e) { e.printStackTrace(); } return file.getName(); }
From source file:com.example.mediastock.util.Utilities.java
/** * Method to save a media file inside the directory typeDir. It writes the bytes of the stream into the file * @param type the directory type: music, video or image * @param context the context//from w w w. j av a2s .c om * @param inputStream the stream * @param id the id of the media file * @return the path of the media file */ public static String saveMediaToInternalStorage(String type, Context context, InputStream inputStream, int id) { ContextWrapper cw = new ContextWrapper(context.getApplicationContext()); File dir = cw.getDir(type + "Dir", Context.MODE_PRIVATE); // Create media file File file; if (type.equals(Utilities.MUSIC_DIR)) file = new File(dir, type + id + ".mp3"); else file = new File(dir, type + id); FileOutputStream fos; try { fos = new FileOutputStream(file); fos.write(Utilities.covertStreamToByte(inputStream)); fos.flush(); fos.close(); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } return file.getName(); }
From source file:com.cloudmine.api.db.RequestDBOpenHelper.java
public static synchronized RequestDBOpenHelper getRequestDBOpenHelper(Context context) { if (requestDBOpenHelper == null) { requestDBOpenHelper = new RequestDBOpenHelper(context.getApplicationContext()); }//from w w w. j a v a 2s.com return requestDBOpenHelper; }
From source file:com.cerema.cloud2.lib.common.accounts.AccountUtils.java
/** * Extracts url server from the account/*from w ww .j av a2 s . c o m*/ * @param context * @param account * @return url server or null on failure * @throws AccountNotFoundException When 'account' is unknown for the AccountManager */ public static String getBaseUrlForAccount(Context context, Account account) throws AccountNotFoundException { AccountManager ama = AccountManager.get(context.getApplicationContext()); String baseurl = ama.getUserData(account, Constants.KEY_OC_BASE_URL); if (baseurl == null) throw new AccountNotFoundException(account, "Account not found", null); return baseurl; }
From source file:com.atinternet.tracker.LifeCycle.java
/** * Init lifecycle/*from ww w . j ava 2 s. co m*/ * * @param context Context */ static void initLifeCycle(Context context) { SharedPreferences preferences = Tracker.getPreferences(); try { versionCode = String.valueOf(context.getPackageManager() .getPackageInfo(context.getApplicationContext().getPackageName(), 0).versionCode); // Not first session if (!preferences.getBoolean(FIRST_SESSION, true) || preferences.getBoolean("ATFirstInitLifecycleDone", false)) { newSessionInit(preferences); } else { SharedPreferences backwardPreferences = context.getSharedPreferences("ATPrefs", Context.MODE_PRIVATE); firstSessionInit(preferences, backwardPreferences); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } preferences.edit().putBoolean("ATFirstInitLifecycleDone", true).apply(); isInitialized = true; }
From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java
/** * ??activity/*from w ww. j a v a 2 s .c o m*/ * * @param context * @return */ @SuppressWarnings("deprecation") public static ComponentName getTheProcessBaseActivity(final Context context) { ActivityManager activityManager = (ActivityManager) context.getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE); RunningTaskInfo task = activityManager.getRunningTasks(1).get(0); if (task.numActivities > 0) { LogUtil.d(TAG, "runningActivity topActivity=" + task.topActivity.getClassName()); LogUtil.d(TAG, "runningActivity baseActivity=" + task.baseActivity.getClassName()); return task.baseActivity; } return null; }
From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java
/** * ????/*from w w w . j ava2 s.co m*/ * * @param context */ public static boolean isAppOnForeground(final Context context) { ActivityManager activityManager = (ActivityManager) context.getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE); String packageName = context.getApplicationContext().getPackageName(); List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); if (appProcesses != null) { for (RunningAppProcessInfo appProcess : appProcesses) { // The name of the process that this object is associated with. if (appProcess.processName.equals(packageName) && appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { return true; } } } return false; }
From source file:ir.keloud.android.lib.common.accounts.AccountUtils.java
/** * Restore the client cookies from accountName * @param accountName/*from w ww. j a v a 2 s .co m*/ * @param client * @param context */ public static void restoreCookies(String accountName, KeloudClient client, Context context) { Log_OC.d(TAG, "Restoring cookies for " + accountName); // Account Manager AccountManager am = AccountManager.get(context.getApplicationContext()); // Get account Account account = null; Account accounts[] = am.getAccounts(); for (Account a : accounts) { if (a.name.equals(accountName)) { account = a; break; } } // Restoring cookies if (account != null) { restoreCookies(account, client, context); } }
From source file:ir.keloud.android.lib.common.accounts.AccountUtils.java
/** * Restore the client cookies/*from w w w. j av a2 s.c om*/ * @param account * @param client * @param context */ public static void restoreCookies(Account account, KeloudClient client, Context context) { Log_OC.d(TAG, "Restoring cookies for " + account.name); // Account Manager AccountManager am = AccountManager.get(context.getApplicationContext()); Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getWebdavUri(); String cookiesString = am.getUserData(account, Constants.KEY_COOKIES); if (cookiesString != null) { String[] cookies = cookiesString.split(";"); if (cookies.length > 0) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = new Cookie(); int equalPos = cookies[i].indexOf('='); cookie.setName(cookies[i].substring(0, equalPos)); cookie.setValue(cookies[i].substring(equalPos + 1)); cookie.setDomain(serverUri.getHost()); // VERY IMPORTANT cookie.setPath(serverUri.getPath()); // VERY IMPORTANT client.getState().addCookie(cookie); } } } }