Example usage for android.content Context getApplicationContext

List of usage examples for android.content Context getApplicationContext

Introduction

In this page you can find the example usage for android.content Context getApplicationContext.

Prototype

public abstract Context getApplicationContext();

Source Link

Document

Return the context of the single, global Application object of the current process.

Usage

From source file:com.amazonaws.utilities.Util.java

/**
 * Gets an instance of the TransferUtility which is constructed using the
 * given Context//from   w  w  w .j a v a2 s .co  m
 * 
 * @param context
 * @return a TransferUtility instance
 */
public static TransferUtility getTransferUtility(Context context) {
    if (sTransferUtility == null) {
        sTransferUtility = new TransferUtility(getS3Client(context.getApplicationContext()),
                context.getApplicationContext());
    }

    return sTransferUtility;
}

From source file:Main.java

public static void createDeskShortCut(Context cxt, String shortCutName, int icon, Class<?> cls) {
    Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutIntent.putExtra("duplicate", false);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
    Parcelable ico = Intent.ShortcutIconResource.fromContext(cxt.getApplicationContext(), icon);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ico);
    Intent intent = new Intent(cxt, cls);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    cxt.sendBroadcast(shortcutIntent);//from   w  w  w.j  av a 2 s.  c  o  m
}

From source file:com.doublesunflower.android.lockcast.ImageManager.java

public static ImageManager getInstance(Context c) {
    if (sInstance == null) {
        sInstance = new ImageManager(c.getApplicationContext());
    }//from w w  w.j  a  v  a2s.  co  m
    return sInstance;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean setProxyLollipop(final Context context, String host, int port) {
    System.setProperty("http.proxyHost", host);
    System.setProperty("http.proxyPort", port + "");
    System.setProperty("https.proxyHost", host);
    System.setProperty("https.proxyPort", port + "");
    try {/*from w  ww .j av  a2  s.  c  o m*/
        Context appContext = context.getApplicationContext();
        Class applictionClass = Class.forName("android.app.Application");
        Field mLoadedApkField = applictionClass.getDeclaredField("mLoadedApk");
        mLoadedApkField.setAccessible(true);
        Object mloadedApk = mLoadedApkField.get(appContext);
        Class loadedApkClass = Class.forName("android.app.LoadedApk");
        Field mReceiversField = loadedApkClass.getDeclaredField("mReceivers");
        mReceiversField.setAccessible(true);
        ArrayMap receivers = (ArrayMap) mReceiversField.get(mloadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object receiver : ((ArrayMap) receiverMap).keySet()) {
                Class clazz = receiver.getClass();
                if (clazz.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
                    onReceiveMethod.invoke(receiver, appContext, intent);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:Main.java

public static void sendBroadcast(Context context, String filter, String name, Serializable serializable) {
    Intent intent = new Intent();
    intent.putExtra(name, serializable);
    intent.setAction(filter);/*from   w w w .ja  v  a 2s. c om*/
    if (mLocalBroadcastManager == null) {
        getLocalBroadcastManager(context.getApplicationContext());
    }
    mLocalBroadcastManager.sendBroadcast(intent);
}

From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java

public static SharedPreferences createNotificationStore(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
}

From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java

/**
 * Access to Singleton object of this class. Creates a new instance if it
 * has not been created yet./*from  w w  w. j  a v a2 s  .c om*/
 */
public static DestinationDbHelper getInstance(Context context) {
    if (sInstance == null) {
        sInstance = new DestinationDbHelper(context.getApplicationContext());
    }
    return sInstance;
}

From source file:at.the.gogo.panoramio.panoviewer.ImageManager.java

public static ImageManager getInstance(final Context c) {
    if (sInstance == null) {
        sInstance = new ImageManager(c.getApplicationContext());
    }//from  w  w w  .j  a  v  a 2  s .  c  o  m
    return sInstance;
}

From source file:com.andrew.apollo.cache.ImageFetcher.java

/**
 * Used to create a singleton of the image fetcher
 *
 * @param context The {@link Context} to use
 * @return A new instance of this class.
 *//* w w w. j  av  a 2  s.com*/
public static final ImageFetcher getInstance(final Context context) {
    if (sInstance == null) {
        sInstance = new ImageFetcher(context.getApplicationContext());
    }
    return sInstance;
}

From source file:Main.java

public static void sendBroadcast(Context context, String filter, Bundle bundle) {
    if (context == null) {
        return;//from  w  ww. j a  va2 s.  c om
    }
    Intent intent = new Intent();
    intent.setAction(filter);
    intent.putExtras(bundle);
    if (mLocalBroadcastManager == null) {
        getLocalBroadcastManager(context.getApplicationContext());
    }
    mLocalBroadcastManager.sendBroadcast(intent);
}