Example usage for android.content Context getString

List of usage examples for android.content Context getString

Introduction

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

Prototype

@NonNull
public final String getString(@StringRes int resId) 

Source Link

Document

Returns a localized string from the application's package's default string table.

Usage

From source file:de.vanita5.twittnuker.util.StatusCodeMessageUtils.java

public static String getTwitterErrorMessage(final Context context, final int code) {
    if (context == null)
        return null;
    final int res_id = TWITTER_ERROR_CODE_MESSAGES.get(code, -1);
    if (res_id > 0)
        return context.getString(res_id);
    return null;/*from www  .  j ava2 s. com*/
}

From source file:edu.mit.media.realityanalysis.fieldtest.MainPipeline.java

public static SharedPreferences getSystemPrefs(Context context) {
    return async(context.getSharedPreferences(context.getString(R.string.prefs_file), MODE_PRIVATE));
}

From source file:com.manning.androidhacks.hack036.util.LaunchEmailUtil.java

public static void launchEmailToIntent(Context context) {
    Intent msg = new Intent(Intent.ACTION_SEND);

    StringBuilder body = new StringBuilder("\n\n----------\n");
    body.append(EnvironmentInfoUtil.getApplicationInfo(context));

    msg.putExtra(Intent.EXTRA_EMAIL, context.getString(R.string.mail_support_feedback_to).split(", "));
    msg.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.mail_support_feedback_subject));
    msg.putExtra(Intent.EXTRA_TEXT, body.toString());

    msg.setType("message/rfc822");
    context.startActivity(Intent.createChooser(msg, context.getString(R.string.pref_sendemail_title)));
}

From source file:Main.java

/**
 * @return null if not existing/*from w  w  w .  j  a v a 2 s . c o m*/
 */
public static String getResourceString(Context context, String name) {

    int nameResourceID = context.getResources().getIdentifier(name, "string",
            context.getApplicationInfo().packageName);

    if (nameResourceID == 0) {
        return null;
    } else {
        return context.getString(nameResourceID);
    }
}

From source file:com.example.igorklimov.popularmoviesdemo.sync.SyncAdapter.java

/**
 * Create a new dummy account for the sync adapter
 *
 * @param context The application context
 *//*from w ww. j  a  v  a2s . c o m*/
public static Account getSyncAccount(Context context) {
    Account newAccount = new Account(context.getString(R.string.app_name),
            context.getString(R.string.acc_sync_type));
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);

    if (accountManager.getPassword(newAccount) == null) {
        if (!accountManager.addAccountExplicitly(newAccount, "", null))
            return null;

        onAccountCreated(newAccount, context);
    }

    return newAccount;
}

From source file:Main.java

public static NotificationCompat.Builder buildNotification(Context context, Class<?> cls, int icon, int title,
        String text) {/* www  . j  av  a 2 s  . c  om*/
    Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(icon)
            .setContentTitle(context.getString(title)).setContentText(text).setAutoCancel(true).setSound(sound)
            .setTicker(text);
    Intent intent = new Intent(context, cls);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context).addParentStack(cls).addNextIntent(intent);
    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);
    return builder;
}

From source file:com.scvngr.levelup.core.net.RequestUtils.java

/**
 * Get the API key for the context passed.
 *
 * @param context the Application context.
 * @return The API key from resources.//from w  ww  .java 2 s.  co m
 */
@NonNull
public static String getApiKey(@NonNull final Context context) {
    final String apiKey = NullUtils.nonNullContract(context.getString(R.string.levelup_api_key));

    if (TextUtils.isEmpty(apiKey)) {
        throw new AssertionError(String.format(Locale.US, "Application must override %s",
                context.getResources().getResourceEntryName(R.string.levelup_api_key)));
    }

    return apiKey;
}

From source file:au.id.micolous.frogjump.Util.java

public static void showToast(Context context, int resId) {
    Looper.prepare();/*w w  w  .  java  2 s  . c  o m*/
    String message = context.getString(resId);
    Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
    toast.show();
}

From source file:com.example.igorklimov.popularmoviesdemo.sync.SyncAdapter.java

private static void configurePeriodicSync(Context context, int syncInterval, int flexTime) {
    String authority = context.getString(R.string.content_authority);
    Account account = getSyncAccount(context);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // we can enable inexact timers in our periodic sync
        SyncRequest request = new SyncRequest.Builder().syncPeriodic(syncInterval, flexTime)
                .setSyncAdapter(account, authority).setExtras(new Bundle()).build();
        ContentResolver.requestSync(request);
    } else {//  w ww  . ja  v a2 s .  c  o  m
        ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval);
    }
}

From source file:Main.java

public static String getResourceString(String name, Context context) {
    int nameResourceID = context.getResources().getIdentifier(name, "string",
            context.getApplicationInfo().packageName);
    if (nameResourceID == 0) {
        throw new IllegalArgumentException("No resource string found with name " + name);
    } else {/*from w w  w . ja va2 s.  c o m*/
        return context.getString(nameResourceID);
    }
}