List of usage examples for android.content Context getApplicationContext
public abstract Context getApplicationContext();
From source file:com.vk.sdk.payments.VKPaymentsServerSender.java
public static VKPaymentsServerSender getInstance(@NonNull Context ctx) { if (sInstance == null) { synchronized (VKPaymentsServerSender.class) { if (sInstance == null) { sInstance = new VKPaymentsServerSender(ctx.getApplicationContext()); }/* www . j a v a 2 s . c o m*/ } } return sInstance; }
From source file:com.android.launcher3.InstallShortcutReceiver.java
private static void queuePendingShortcutInfo(PendingInstallShortcutInfo info, Context context) { // Queue the item up for adding if launcher has not loaded properly yet LauncherAppState.setApplicationContext(context.getApplicationContext()); LauncherAppState app = LauncherAppState.getInstance(); boolean launcherNotLoaded = app.getModel().getCallback() == null; String spKey = LauncherAppState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); addToInstallQueue(sp, info);//w w w . j a v a 2 s . c om if (!mUseInstallQueue && !launcherNotLoaded) { flushInstallQueue(context); } }
From source file:com.stv.launcher.receiver.InstallShortcutReceiver.java
private static void queuePendingShortcutInfo(PendingInstallShortcutInfo info, Context context) { // Queue the item up for adding if launcher has not loaded properly yet LauncherState.setApplicationContext(context.getApplicationContext()); LauncherState app = LauncherState.getInstance(); boolean launcherNotLoaded = app.getModel().getCallback() == null; String spKey = LauncherState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); addToInstallQueue(sp, info);/* ww w.j a v a 2s.c om*/ if (!mUseInstallQueue && !launcherNotLoaded) { flushInstallQueue(context); } }
From source file:Main.java
/** * Returns a Java File initialized to a directory of given name * at the root storage location, with preference to external storage. * If the directory did not exist, it will be created at the conclusion of this call. * If a file with conflicting name exists, this method returns null; * * @param c the context to determine the internal storage location, if external is unavailable * @param directory_name the name of the directory desired at the storage location * @return a File pointing to the storage directory, or null if a file with conflicting name * exists//from w ww .ja v a2 s .co m */ public static File getRootStorageDirectory(Context c, String directory_name) { File result; // First, try getting access to the sdcard partition if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Log.d(TAG, "Using sdcard"); result = new File(Environment.getExternalStorageDirectory(), directory_name); } else { // Else, use the internal storage directory for this application Log.d(TAG, "Using internal storage"); result = new File(c.getApplicationContext().getFilesDir(), directory_name); } if (!result.exists()) result.mkdir(); else if (result.isFile()) { return null; } Log.d("getRootStorageDirectory", result.getAbsolutePath()); return result; }
From source file:com.jerrellmardis.amphitheatre.util.Utils.java
public static void backupDatabase(Context ctx) { try {/*from w w w.java 2 s. com*/ File sd = Environment.getExternalStorageDirectory(); File data = Environment.getDataDirectory(); if (sd.canWrite()) { String currentDBPath = "//data//" + ctx.getApplicationContext().getPackageName() + "//databases//amphitheatre.db"; String backupDBPath = "amphitheatre.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.appsimobile.appsii.module.weather.ImageDownloadHelper.java
public synchronized static ImageDownloadHelper getInstance(Context context) { if (sImageDownloadHelper == null) { sImageDownloadHelper = new ImageDownloadHelper(context.getApplicationContext()); }//from ww w . ja v a 2s.c om return sImageDownloadHelper; }
From source file:cn.sharesdk.analysis.EventManager.java
public static synchronized void init(Context c) { if (context == null && c != null) { context = c.getApplicationContext(); dbHelper = PreferencesHelper.getInstance(context); deviceHelper = DeviceHelper.getInstance(context); isServiceConnect(context);/*from w ww . ja v a2s. co m*/ } else if (context == null && c == null) { Ln.e("Context is null", "call setContext to set it"); } }
From source file:com.google.sample.castcompanionlibrary.utils.Utils.java
/** * A utility method to show a simple error dialog. The textual content of the dialog is * provided through the passed-in resource id. * * @param context// w ww .j a v a 2 s . co m * @param resourceId */ public static final void showErrorDialog(Context context, int resourceId) { //showErrorDialog(context, context.getString(resourceId)); showToast(context.getApplicationContext(), resourceId); }
From source file:Main.java
/** * Generate a SSLSocketFactory wich checks the certificate given * @param context Context to use// www . ja v a 2s. co m * @param rResource int with url of the resource to read the certificate * @parma password String to use with certificate * @return SSLSocketFactory generated to validate this certificate */ public static SSLSocketFactory newSslSocketFactory(Context context, int rResource, String password) throws CertificateException, NoSuchProviderException, KeyStoreException, NoSuchAlgorithmException, IOException, UnrecoverableKeyException, KeyManagementException { // Get an instance of the Bouncy Castle KeyStore format KeyStore trusted = KeyStore.getInstance("BKS"); // Get the raw resource, which contains the keystore with // your trusted certificates (root and any intermediate certs) InputStream is = context.getApplicationContext().getResources().openRawResource(rResource); CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509", "BC"); X509Certificate cert = (X509Certificate) certificateFactory.generateCertificate(is); String alias = "alias";//cert.getSubjectX500Principal().getName(); KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null); trustStore.setCertificateEntry(alias, cert); KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509"); kmf.init(trustStore, null); KeyManager[] keyManagers = kmf.getKeyManagers(); TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509"); tmf.init(trustStore); TrustManager[] trustManagers = tmf.getTrustManagers(); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(keyManagers, trustManagers, null); return sslContext.getSocketFactory(); }
From source file:com.cyberocw.habittodosecretary.file.StorageHelper.java
public static File getSharedPreferencesFile(Context mContext) { File appData = mContext.getFilesDir().getParentFile(); String packageName = mContext.getApplicationContext().getPackageName(); return new File(appData + System.getProperty("file.separator") + "shared_prefs" + System.getProperty("file.separator") + packageName + "_preferences.xml"); }