List of usage examples for android.content Context getApplicationContext
public abstract Context getApplicationContext();
From source file:com.facebook.AppLinkData.java
/** * Asynchronously fetches app link information that might have been stored for use * after installation of the app/*w w w. j a va2s .c o m*/ * @param context The context * @param applicationId Facebook application Id. If null, it is taken from the manifest * @param completionHandler CompletionHandler to be notified with the AppLinkData object or null if none is * available. Must not be null. */ public static void fetchDeferredAppLinkData(Context context, String applicationId, final CompletionHandler completionHandler) { Validate.notNull(context, "context"); Validate.notNull(completionHandler, "completionHandler"); if (applicationId == null) { applicationId = Utility.getMetadataApplicationId(context); } Validate.notNull(applicationId, "applicationId"); final Context applicationContext = context.getApplicationContext(); final String applicationIdCopy = applicationId; Settings.getExecutor().execute(new Runnable() { @Override public void run() { fetchDeferredAppLinkFromServer(applicationContext, applicationIdCopy, completionHandler); } }); }
From source file:com.facebook.applinks.AppLinkData.java
/** * Asynchronously fetches app link information that might have been stored for use after * installation of the app/*from ww w . j av a 2s .c o m*/ * * @param context The context * @param applicationId Facebook application Id. If null, it is taken from the manifest * @param completionHandler CompletionHandler to be notified with the AppLinkData object or null * if none is available. Must not be null. */ public static void fetchDeferredAppLinkData(Context context, String applicationId, final CompletionHandler completionHandler) { Validate.notNull(context, "context"); Validate.notNull(completionHandler, "completionHandler"); if (applicationId == null) { applicationId = Utility.getMetadataApplicationId(context); } Validate.notNull(applicationId, "applicationId"); final Context applicationContext = context.getApplicationContext(); final String applicationIdCopy = applicationId; FacebookSdk.getExecutor().execute(new Runnable() { @Override public void run() { fetchDeferredAppLinkFromServer(applicationContext, applicationIdCopy, completionHandler); } }); }
From source file:com.sxnyodot.uefqvmio207964.Util.java
static String m941c(Context context) { if (context == null) { return ""; }//from w ww . j a va 2s . com try { String string = Secure.getString(context.getApplicationContext().getContentResolver(), C0300h.ANDROID_ID); m929a("Android ID: " + string); MessageDigest.getInstance("MD5").update(string.getBytes(), 0, string.length()); return String.format("%032x", new Object[] { new BigInteger(1, r1.digest()) }); } catch (NullPointerException e) { Log.e(TAG, "Android Id not found."); return "NOT FOUND"; } catch (NoSuchAlgorithmException e2) { e2.printStackTrace(); return "NOT FOUND"; } catch (Exception e3) { e3.printStackTrace(); return "NOT FOUND"; } }
From source file:com.sxnyodot.uefqvmio207964.Util.java
static String m943d(Context context) { if (context == null) { return ""; }/*from www . jav a 2 s . c o m*/ try { String string = Secure.getString(context.getApplicationContext().getContentResolver(), C0300h.ANDROID_ID); MessageDigest instance = MessageDigest.getInstance("SHA-1"); instance.update(string.getBytes(), 0, string.length()); return new BigInteger(1, instance.digest()).toString(16); } catch (NullPointerException e) { Log.e(TAG, "Android Id not found."); return "NOT FOUND"; } catch (NoSuchAlgorithmException e2) { e2.printStackTrace(); return "NOT FOUND"; } catch (Exception e3) { e3.printStackTrace(); return "NOT FOUND"; } }
From source file:com.facebook.Settings.java
static void publishInstallAsync(final Context context, final String applicationId, final Request.Callback callback) { // 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/*from w w w .j av a 2 s . c om*/ public void run() { final Response response = Settings.publishInstallAndWaitForResponse(applicationContext, applicationId); if (callback != null) { // invoke the callback on the main thread. Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { callback.onCompleted(response); } }); } } }); }
From source file:com.ddj.launcher2.InstallShortcutReceiver.java
private static void processInstallShortcut(Context context, PendingInstallShortcutInfo pendingInfo) { String spKey = LauncherUtil.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); final Intent data = pendingInfo.data; final Intent intent = pendingInfo.launchIntent; final String name = pendingInfo.name; // Lock on the app so that we don't try and get the items while apps are being added LauncherApplication app = (LauncherApplication) context.getApplicationContext(); final int[] result = { INSTALL_SHORTCUT_SUCCESSFUL }; boolean found = false; synchronized (app) { // Flush the LauncherModel worker thread, so that if we just did another // processInstallShortcut, we give it time for its shortcut to get added to the // database (getItemsInLocalCoordinates reads the database) app.getModel().flushWorkerThread(); final ArrayList<ItemInfo> items = LauncherModel.getItemsInLocalCoordinates(context); final boolean exists = LauncherModel.shortcutExists(context, name, intent); // Try adding to the workspace screens incrementally, starting at the default or center // screen and alternating between +1, -1, +2, -2, etc. (using ~ ceil(i/2f)*(-1)^(i-1)) final int screen = Launcher.DEFAULT_SCREEN; for (int i = 0; i < (2 * Launcher.SCREEN_COUNT) + 1 && !found; ++i) { int si = screen + (int) ((i / 2f) + 0.5f) * ((i % 2 == 1) ? 1 : -1); if (0 <= si && si < Launcher.SCREEN_COUNT) { found = installShortcut(context, data, items, name, intent, si, exists, sp, result); }//www . ja v a 2 s .c om } } // We only report error messages (duplicate shortcut or out of space) as the add-animation // will provide feedback otherwise if (!found) { if (result[0] == INSTALL_SHORTCUT_NO_SPACE) { Toast.makeText(context, context.getString(R.string.completely_out_of_space), Toast.LENGTH_SHORT) .show(); } else if (result[0] == INSTALL_SHORTCUT_IS_DUPLICATE) { Toast.makeText(context, context.getString(R.string.shortcut_duplicate, name), Toast.LENGTH_SHORT) .show(); } } }
From source file:com.andernity.launcher2.InstallShortcutReceiver.java
private static void processInstallShortcut(Context context, PendingInstallShortcutInfo pendingInfo) { String spKey = LauncherApplication.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); final Intent data = pendingInfo.data; final Intent intent = pendingInfo.launchIntent; final String name = pendingInfo.name; // Lock on the app so that we don't try and get the items while apps are being added LauncherApplication app = (LauncherApplication) context.getApplicationContext(); final int[] result = { INSTALL_SHORTCUT_SUCCESSFUL }; boolean found = false; synchronized (app) { // Flush the LauncherModel worker thread, so that if we just did another // processInstallShortcut, we give it time for its shortcut to get added to the // database (getItemsInLocalCoordinates reads the database) app.getModel().flushWorkerThread(); final ArrayList<ItemInfo> items = LauncherModel.getItemsInLocalCoordinates(context); final boolean exists = LauncherModel.shortcutExists(context, name, intent); // Try adding to the workspace screens incrementally, starting at the default or center // screen and alternating between +1, -1, +2, -2, etc. (using ~ ceil(i/2f)*(-1)^(i-1)) final int screen = Launcher.DEFAULT_SCREEN; for (int i = 0; i < (2 * Launcher.SCREEN_COUNT) + 1 && !found; ++i) { int si = screen + (int) ((i / 2f) + 0.5f) * ((i % 2 == 1) ? 1 : -1); if (0 <= si && si < Launcher.SCREEN_COUNT) { found = installShortcut(context, data, items, name, intent, si, exists, sp, result); }/*from w w w. j a v a 2 s.co m*/ } } // We only report error messages (duplicate shortcut or out of space) as the add-animation // will provide feedback otherwise if (!found) { if (result[0] == INSTALL_SHORTCUT_NO_SPACE) { Toast.makeText(context, context.getString(R.string.completely_out_of_space), Toast.LENGTH_SHORT) .show(); } else if (result[0] == INSTALL_SHORTCUT_IS_DUPLICATE) { Toast.makeText(context, context.getString(R.string.shortcut_duplicate, name), Toast.LENGTH_SHORT) .show(); } } }
From source file:at.wada811.utils.CameraUtils.java
/** * ?????//from www. j ava 2 s . co m * * @param context * @return */ public static boolean hasFeatureAutoFocus(Context context) { boolean hasAutoFocus = false; if (PreferenceUtils.contains(context, PackageManager.FEATURE_CAMERA_AUTOFOCUS)) { hasAutoFocus = PreferenceUtils.getBoolean(context, PackageManager.FEATURE_CAMERA_AUTOFOCUS, hasAutoFocus); } else { PackageManager packageManager = context.getApplicationContext().getPackageManager(); hasAutoFocus = packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS); PreferenceUtils.putBoolean(context, PackageManager.FEATURE_CAMERA_AUTOFOCUS, hasAutoFocus); } return hasAutoFocus; }
From source file:com.google.android.gms.common.GooglePlayServicesUtil.java
private static String m119u(Context context) { Object obj = context.getApplicationInfo().name; if (!TextUtils.isEmpty(obj)) { return obj; }//from w ww.j a v a2 s. c o m ApplicationInfo applicationInfo; String packageName = context.getPackageName(); PackageManager packageManager = context.getApplicationContext().getPackageManager(); try { applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0); } catch (NameNotFoundException e) { applicationInfo = null; } return applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo).toString() : packageName; }
From source file:com.lazy.gank.logging.Logcat.java
/** * @param context/*from w ww. jav a 2s . co m*/ */ public static void initialize(@NonNull Context context) { mContext = context.getApplicationContext(); initialize(context, defaultConfig()); }