List of usage examples for android.content Context getApplicationContext
public abstract Context getApplicationContext();
From source file:com.dwdesign.tweetings.app.TweetingsApplication.java
public static TweetingsApplication getInstance(final Context context) { return context != null ? (TweetingsApplication) context.getApplicationContext() : null; }
From source file:m2.android.archetype.example.FacebookSdk.Settings.java
public static void publishInstallAsync(final Context context, final String applicationId) { // grab the application context ahead of time, since we will return to the caller immediately. final Context applicationContext = context.getApplicationContext(); Settings.getExecutor().execute(new Runnable() { @Override/* ww w .j a v a 2s . co m*/ public void run() { Settings.publishInstallAndWait(applicationContext, applicationId); } }); }
From source file:net.named_data.nfd.LogcatSettingsManager.java
/** * Gets the singleton logcat settings manager. * * @param context Current application context * @return The singleton settings manager *///from www . j a va2s.c om public static LogcatSettingsManager get(Context context) { if (s_logcatSettingsManager == null) { s_logcatSettingsManager = new LogcatSettingsManager(context.getApplicationContext()); } return s_logcatSettingsManager; }
From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java
/** * ???????//from w w w . ja va 2s .c o m * * @param context * @return */ public static boolean checkTheProcess(final Context context, String endProcessName) { ActivityManager activityManager = (ActivityManager) context.getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE); int myPid = android.os.Process.myPid(); List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); if (appProcesses != null) { for (RunningAppProcessInfo appProcess : appProcesses) { if (myPid == appProcess.pid) { LogUtil.d(TAG, "process.pid appProcess.processName=" + appProcess.processName + ", endProcessName=" + endProcessName); if (appProcess.processName.endsWith(endProcessName)) { return true; } break; } } } return false; }
From source file:com.twentyoneechoes.borges.util.Utils.java
public static void backupDatabase(Context ctx) { try {//from w w w.ja v a2s . c om File sd = Environment.getExternalStorageDirectory(); File data = Environment.getDataDirectory(); if (sd.canWrite()) { String currentDBPath = "//data//" + ctx.getApplicationContext().getPackageName() + "//databases//borges.db"; String backupDBPath = "borges.db"; File currentDB = new File(data, currentDBPath); File backupDB = new File(sd, backupDBPath); if (currentDB.exists()) { FileChannel src = new FileInputStream(currentDB).getChannel(); FileChannel dst = new FileOutputStream(backupDB).getChannel(); dst.transferFrom(src, 0, src.size()); src.close(); dst.close(); } } } catch (Exception e) { Log.i(Utils.class.getSimpleName(), "Unable to backup database"); } }
From source file:com.cerema.cloud2.lib.common.accounts.AccountUtils.java
/** * Restore the client cookies from accountName * @param accountName//from ww w. j a v a 2 s .c om * @param client * @param context */ public static void restoreCookies(String accountName, OwnCloudClient 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:com.cerema.cloud2.lib.common.accounts.AccountUtils.java
/** * Restore the client cookies/*ww w . j a v a 2s .c o m*/ * @param account * @param client * @param context */ public static void restoreCookies(Account account, OwnCloudClient 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); } } } }
From source file:edu.nd.darts.cimon.database.CimonDatabaseAdapter.java
public static synchronized CimonDatabaseAdapter getInstance(Context context) { if (DebugLog.DEBUG) Log.d(TAG, "CimonDatabaseAdapter.getInstance - get single instance"); if (mInstance == null) { mInstance = new CimonDatabaseAdapter(context.getApplicationContext()); }/*from w w w . j a v a 2 s.c o m*/ return mInstance; }
From source file:com.twotoasters.android.horizontalimagescroller.io.ImageCacheManager.java
public static ImageCacheManager getInstance(Context context) { if (instance == null) { instance = new ImageCacheManager(context.getApplicationContext()); }/* w w w . ja va2s. c o m*/ return instance; }
From source file:com.vg.api.VGClient.java
public static void initBilling(Context con, String appLicenseKey, ConsumableCallBack ccb) { IABKEY = appLicenseKey;//from ww w .j a v a 2s . com if (ccb != null) { consumableImpl = ccb; } mCurrentAndroidContext = con.getApplicationContext(); //start in app purchase background service con.startService(new Intent(con, IABHelperService.class)); }