Example usage for android.app Activity getApplicationContext

List of usage examples for android.app Activity getApplicationContext

Introduction

In this page you can find the example usage for android.app Activity getApplicationContext.

Prototype

@Override
    public Context getApplicationContext() 

Source Link

Usage

From source file:Main.java

public static String getFilesDir(Activity activity) {
    return activity.getApplicationContext().getFilesDir().getAbsolutePath();
}

From source file:Main.java

public static Context getContext(Activity activity) {
    return activity.getApplicationContext();
}

From source file:Main.java

public static String getDeviceType(Activity act) {
    if (isTablet(act.getApplicationContext()))
        return "Tablet";
    else/*from   w ww. ja  va  2 s . c  om*/
        return "Phone";
}

From source file:Main.java

public static void makeToast(Activity currentActivity, String message) {
    Toast.makeText(currentActivity.getApplicationContext(), message, Toast.LENGTH_SHORT).show();

}

From source file:Main.java

public static String GetAppName(Activity act) {
    final PackageManager pm = act.getApplicationContext().getPackageManager();

    ApplicationInfo ai;/*from   w  w w . j a v  a  2 s  .c o m*/
    try {
        ai = pm.getApplicationInfo(act.getPackageName(), 0);
    } catch (final NameNotFoundException e) {
        ai = null;
    }
    final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "unknown");
    return applicationName;
}

From source file:Main.java

public static String getDeviceType(Activity act) {
    return getDeviceType(act.getApplicationContext());
}

From source file:Main.java

public static void showDialogOkWithGoBack(String title, String message, final Activity activity) {
    if (activity.getApplicationContext() != null) {
        AlertDialog.Builder adb = new AlertDialog.Builder(activity);
        adb.setTitle(title);//ww w .  ja v a 2s.  com
        adb.setMessage(message);
        adb.setCancelable(false);
        adb.setNeutralButton("OK", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
                //activity.onBackPressed();
            }
        });
        AlertDialog ad = adb.create();
        ad.setVolumeControlStream(AudioManager.STREAM_MUSIC);
        ad.show();
    }
}

From source file:Main.java

public static String getDeviceID(Activity a) {
    TelephonyManager tm = (TelephonyManager) a.getApplicationContext()
            .getSystemService(Context.TELEPHONY_SERVICE);
    String id = tm.getDeviceId();
    if (id == null)
        id = "DefaultTwitchUser";
    return Integer.toHexString(id.hashCode());
}

From source file:Main.java

private static SharedPreferences getSharedPref(Activity activity) {
    return PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
}

From source file:Main.java

public static boolean isNetworkAvailable(Activity activity) {
    Context context = activity.getApplicationContext();
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    if (connectivityManager == null) {
        return false;
    } else {/*from  w  ww  .j a  v  a 2  s  .c o m*/
        NetworkInfo[] networkInfo = connectivityManager.getAllNetworkInfo();

        if (networkInfo != null && networkInfo.length > 0) {
            for (int i = 0; i < networkInfo.length; i++) {

                if (networkInfo[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
    }
    return false;
}