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

StringgetContactName(Context ctx, String phoneNumber)
get Contact Name
final ContentResolver cr = ctx.getContentResolver();
final Uri uri = Uri.withAppendedPath(
        PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
Cursor cursor = null;
String contactName = phoneNumber;
try {
    cursor = cr.query(uri,
            new String[] { PhoneLookup.DISPLAY_NAME }, null, null,
...
PaintgetCornerLightPaint(Context context)
get Corner Light Paint
final Paint cornerPaint = new Paint();
cornerPaint.setColor(DEFAULT_CORNER_LIGHT_COLOR);
cornerPaint.setStyle(Paint.Style.FILL);
cornerPaint.setAntiAlias(true);
return cornerPaint;
floatgetCornerOffset(Context context)
get Corner Offset
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
        DEFAULT_CORNER_OFFSET, context.getResources()
                .getDisplayMetrics());
PaintgetCornerPaint(Context context)
get Corner Paint
final Paint cornerPaint = new Paint();
cornerPaint.setColor(DEFAULT_CORNER_COLOR);
cornerPaint.setStyle(Paint.Style.FILL);
cornerPaint.setAntiAlias(true);
return cornerPaint;
floatgetCornerRadius(Context context)
get Corner Radius
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
        DEFAULT_CORNER_RADIUS, context.getResources()
                .getDisplayMetrics());
RunningAppProcessInfogetCurProcess(Context context)
get Cur Process
final int pid = android.os.Process.myPid();
final ActivityManager mActivityManager = (ActivityManager) context
        .getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningAppProcessInfo> runningAppProcesses = mActivityManager
        .getRunningAppProcesses();
RunningAppProcessInfo result = null;
for (ActivityManager.RunningAppProcessInfo appProcess : runningAppProcesses) {
    if (appProcess.pid == pid) {
...
StringgetCurrentHome(Context c)
get Current Home
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = c.getPackageManager().resolveActivity(
        intent, PackageManager.MATCH_DEFAULT_ONLY);
return resolveInfo.activityInfo.packageName;
HashMapgetCurrentLocationByName( Context context)
public static HashMap getCurrentLocationByName(Context context)

This method will return the address of the location in the form of hash map in key value pair, Values of the address can be retrieved using keys.
HashMap<String, String> addressValues = new HashMap<String, String>();
double latitude = 0.0;
double longtiude = 0.0;
LocationManager locationManager = (LocationManager) context
        .getSystemService(Context.LOCATION_SERVICE);
Location quickLocation = locationManager
        .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (quickLocation != null) {
...
StringgetCurrentSsid(Context context)
get Current Ssid
String ssid = null;
ConnectivityManager connManager = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connManager
        .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo.isConnected()) {
    final WifiManager wifiManager = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);
...
FilegetDataFile(Context context, String fileName)
get Data File
File file = new File(getDatafilesStorageDirectory(context),
        fileName);
return file;