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 a S3 client which is constructed using the given
 * Context./*from   w  w  w .j ava 2 s . c o m*/
 *
 * @param context An Context instance.
 * @return A default S3 client.
 */
public static AmazonS3Client getS3Client(Context context) {
    if (sS3Client == null) {
        sS3Client = new AmazonS3Client(getCredProvider(context.getApplicationContext()));
    }
    return sS3Client;
}

From source file:Main.java

public static void sendBroadcast(Context context, String filter, String name, int value) {
    Intent intent = new Intent();
    intent.putExtra(name, value);/*w ww . ja  va  2s. c  o m*/
    intent.setAction(filter);
    if (mLocalBroadcastManager == null) {
        getLocalBroadcastManager(context.getApplicationContext());
    }
    mLocalBroadcastManager.sendBroadcast(intent);
}

From source file:Main.java

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

From source file:Main.java

public static void sendBroadcast(Context context, String filter, String name, long value) {
    Intent intent = new Intent();
    intent.putExtra(name, value);/*from w  w  w.java2 s.  com*/
    intent.setAction(filter);
    if (mLocalBroadcastManager == null) {
        getLocalBroadcastManager(context.getApplicationContext());
    }
    mLocalBroadcastManager.sendBroadcast(intent);
}

From source file:Main.java

public static void sendBroadcast(Context context, String filter, String name, String value) {
    Intent intent = new Intent();
    intent.putExtra(name, value);/*from w  w  w.j a v  a2  s .  co  m*/
    intent.setAction(filter);
    if (mLocalBroadcastManager == null) {
        getLocalBroadcastManager(context.getApplicationContext());
    }
    mLocalBroadcastManager.sendBroadcast(intent);
}

From source file:com.scoreflex.ScoreflexGcmClient.java

protected static Notification buildNotification(String text, Context context, int iconResource,
        PendingIntent pendingIntent) {/*www. j a  v a2  s  .c  o  m*/
    final PackageManager pm = context.getApplicationContext().getPackageManager();
    ApplicationInfo ai;
    try {
        ai = pm.getApplicationInfo(context.getPackageName(), 0);
    } catch (final NameNotFoundException e) {
        ai = null;
    }
    final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setContentTitle(applicationName).setContentText(text).setSmallIcon(iconResource);

    mBuilder.setContentIntent(pendingIntent);
    Notification notification = mBuilder.build();
    notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    return notification;
}

From source file:key.secretkey.utils.PasswordStorage.java

public static Repository initialize(Context context) {
    File dir = getRepositoryDirectory(context);
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());

    if (dir == null) {
        return null;
    }/*from   w  w  w. j  a va  2s  .  c om*/

    // uninitialize the repo if the dir does not exist or is absolutely empty
    if (!dir.exists() || !dir.isDirectory() || FileUtils.listFiles(dir, null, false).isEmpty()) {
        settings.edit().putBoolean("repository_initialized", false).apply();
    }

    if (!PasswordStorage.getPasswords(dir).isEmpty()) {
        settings.edit().putBoolean("repository_initialized", true).apply();
    }

    // create the repository static variable in PasswordStorage
    return PasswordStorage.getRepository(new File(dir.getAbsolutePath() + "/.git"));
}

From source file:com.mobiperf.AccountSelector.java

/**
 * Return the list of account names for users to select
 *///from  ww w . j  ava  2  s  .  co  m
public static String[] getAccountList(Context context) {
    AccountManager accountManager = AccountManager.get(context.getApplicationContext());
    Account[] accounts = accountManager.getAccountsByType(ACCOUNT_TYPE);
    int numAccounts = accounts == null ? 1 : accounts.length + 1;
    String[] accountNames = new String[numAccounts];
    for (int i = 0; i < accounts.length; i++) {
        accountNames[i] = accounts[i].name;
    }
    accountNames[numAccounts - 1] = context.getString(R.string.defaultUser);
    return accountNames;
}

From source file:com.num.mobiperf.AccountSelector.java

/**
 * Return the list of account names for users to select
 *///from   w ww.  j  ava 2  s .  co  m
public static String[] getAccountList(Context context) {
    AccountManager accountManager = AccountManager.get(context.getApplicationContext());
    Account[] accounts = accountManager.getAccountsByType(ACCOUNT_TYPE);
    int numAccounts = accounts == null ? 1 : accounts.length + 1;
    String[] accountNames = new String[numAccounts];
    for (int i = 0; i < accounts.length; i++) {
        accountNames[i] = accounts[i].name;
    }
    accountNames[numAccounts - 1] = "Anonymous";
    return accountNames;
}

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

/**
 * Gets an instance of CognitoCachingCredentialsProvider which is
 * constructed using the given Context.// w ww.  j a  va 2 s  . c om
 *
 * @param context An Context instance.
 * @return A default credential provider.
 */
private static CognitoCachingCredentialsProvider getCredProvider(Context context) {
    if (sCredProvider == null) {
        sCredProvider = new CognitoCachingCredentialsProvider(context.getApplicationContext(),
                Constants.COGNITO_POOL_ID, Regions.US_EAST_1);
    }
    return sCredProvider;
}