Android Utililty Methods Context Get

List of utility methods to do Context Get

Description

The list of methods to do Context Get are organized into topic(s).

Method

intgetIntSPR(String key, Context context)
get Int SPR
SharedPreferences preferences = PreferenceManager
        .getDefaultSharedPreferences(context);
return preferences.getInt(key, 0);
LocationgetLastKnownLocation(Context context)
get Last Known Location
LocationManager lm = (LocationManager) context
        .getSystemService(Context.LOCATION_SERVICE);
List<String> providers = lm.getProviders(true);
SharedPreferences settings = PreferenceManager
        .getDefaultSharedPreferences(context);
SharedPreferences.Editor settingsEditor = settings.edit();
Location loc = null;
for (int i = providers.size() - 1; i >= 0; i--) {
...
PaintgetLineErrorPaint(Context context)
get Line Error Paint
final float lineThicknessPx = TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_DIP, DEFAULT_LINE_THICKNESS,
        context.getResources().getDisplayMetrics());
final Paint borderPaint = new Paint();
borderPaint.setColor(DEFAULT_LINE_ERROR_COLOR);
borderPaint.setStrokeWidth(lineThicknessPx);
borderPaint.setStyle(Paint.Style.STROKE);
borderPaint.setAntiAlias(true);
...
PaintgetLinePaint(Context context)
get Line Paint
final float lineThicknessPx = TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_DIP, DEFAULT_LINE_THICKNESS,
        context.getResources().getDisplayMetrics());
final Paint borderPaint = new Paint();
borderPaint.setColor(DEFAULT_LINE_COLOR);
borderPaint.setStrokeWidth(lineThicknessPx);
borderPaint.setStyle(Paint.Style.STROKE);
borderPaint.setAntiAlias(true);
...
floatgetLineThickness(Context context)
get Line Thickness
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
        DEFAULT_LINE_THICKNESS, context.getResources()
                .getDisplayMetrics());
LocationProvidergetLocationProvider(Context context)
get Location Provider
if (context != null) {
    LocationProvider networkProvider = null;
    LocationProvider gpsProvider = null;
    LocationManager lm = (LocationManager) context
            .getSystemService(Context.LOCATION_SERVICE);
    if (lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        networkProvider = lm
                .getProvider(LocationManager.NETWORK_PROVIDER);
...
LonggetLongSPR(String key, Context context)
get Long SPR
SharedPreferences preferences = PreferenceManager
        .getDefaultSharedPreferences(context);
return preferences.getLong(key, Long.MAX_VALUE);
intgetMemoryClass(Context context)
get Memory Class
return ((ActivityManager) context
        .getSystemService(Context.ACTIVITY_SERVICE))
        .getMemoryClass();
intgetMinFontSize(Context context)
get Min Font Size
retrieveDisplayMetrics(context);
float sys_scale = context.getResources().getConfiguration().fontScale;
return (int) (MIN_FONT_SIZE * _display_metrics.density
        * STANDARD_DPI * sys_scale);
PackageInfogetMobilityPackageInfo(Context context)
Returns the mobility package info if mobiliy and accelservice exist
try {
    PackageManager pm = context.getPackageManager();
    return pm.getPackageInfo("org.ohmage.mobility", 0);
} catch (PackageManager.NameNotFoundException e) {
return null;