private static Context getContext() { return Parse.getApplicationContext(); }
static boolean hasPermission(String permission) { return (getApplicationContext().checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED); }
Context context = Parse.getApplicationContext(); intent.setPackage(context.getPackageName()); context.sendBroadcast(intent);
/** * Asynchronously fetches the current location of the device. * <p> * This will request location updates from the best provider that match the given criteria * and return the first location received. * <p> * You can customize the criteria to meet your specific needs. * * For higher accuracy, you can set {@link Criteria#setAccuracy(int)}, however result in longer * times for a fix. * * For better battery efficiency and faster location fixes, you can set * {@link Criteria#setPowerRequirement(int)}, however, this will result in lower accuracy. * * @param timeout The number of milliseconds to allow before timing out. * @param criteria The application criteria for selecting a location provider. * @return A Task that is resolved when a location is found. * @see android.location.LocationManager#getBestProvider(android.location.Criteria, boolean) * @see android.location.LocationManager#requestLocationUpdates(String, long, float, android.location.LocationListener) */ public static Task<ParseGeoPoint> getCurrentLocationInBackground(long timeout, Criteria criteria) { return LocationNotifier.getCurrentLocationAsync(Parse.getApplicationContext(), timeout, criteria) .onSuccess(new Continuation<Location, ParseGeoPoint>() { @Override public ParseGeoPoint then(Task<Location> task) { Location location = task.getResult(); return new ParseGeoPoint(location.getLatitude(), location.getLongitude()); } }); }
private void updateVersionInfo() { synchronized (mutex) { try { Context context = Parse.getApplicationContext(); String packageName = context.getPackageName(); PackageManager pm = context.getPackageManager(); PackageInfo pkgInfo = pm.getPackageInfo(packageName, 0); String appVersion = pkgInfo.versionName; String appName = pm.getApplicationLabel(pm.getApplicationInfo(packageName, 0)).toString(); if (packageName != null && !packageName.equals(get(KEY_APP_IDENTIFIER))) { performPut(KEY_APP_IDENTIFIER, packageName); } if (appName != null && !appName.equals(get(KEY_APP_NAME))) { performPut(KEY_APP_NAME, appName); } if (appVersion != null && !appVersion.equals(get(KEY_APP_VERSION))) { performPut(KEY_APP_VERSION, appVersion); } } catch (PackageManager.NameNotFoundException e) { PLog.w(TAG, "Cannot load package info; will not be saved to installation"); } } }
/** * Asynchronously fetches the current location of the device. * <p> * This will use a default {@link Criteria} with no accuracy or power requirements, which will * generally result in slower, but more accurate location fixes. * <p/> * <strong>Note:</strong> If GPS is the best provider, it might not be able to locate the device * at all and timeout. * * @param timeout The number of milliseconds to allow before timing out. * @return A Task that is resolved when a location is found. * @see android.location.LocationManager#getBestProvider(android.location.Criteria, boolean) * @see android.location.LocationManager#requestLocationUpdates(String, long, float, android.location.LocationListener) */ public static Task<ParseGeoPoint> getCurrentLocationInBackground(long timeout) { Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.NO_REQUIREMENT); criteria.setPowerRequirement(Criteria.NO_REQUIREMENT); return LocationNotifier.getCurrentLocationAsync(Parse.getApplicationContext(), timeout, criteria) .onSuccess(new Continuation<Location, ParseGeoPoint>() { @Override public ParseGeoPoint then(Task<Location> task) { Location location = task.getResult(); return new ParseGeoPoint(location.getLatitude(), location.getLongitude()); } }); }
Context context = Parse.getApplicationContext(); String packageName = context.getPackageName(); PackageManager pm = context.getPackageManager();
/** * @deprecated Please use {@link #initialize(Context)} instead. */ @Deprecated public static void initialize() { initialize(Parse.getApplicationContext()); }
/** * @deprecated Please use {@link #initialize(Context, String)} instead. */ @Deprecated public static void initialize(String appId) { initialize(Parse.getApplicationContext(), appId); }