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:no.ntnu.wifimanager.ServerUtilities.java

/**
 * Unregister this account/device pair within the server.
 *///from   w w w  .ja  va2s  .c  o  m
public static void unregister(final Context context, final String regId) {
    Log.i(LOG_TAG, "unregistering device (regId = " + regId + ")");
    String serverUrl = URL_SERVER + "/unregister";
    Map<String, String> params = new HashMap<String, String>();
    params.put("regId", regId);
    try {
        HTTPpost(serverUrl, params, HTTP_CONTENT_TYPE_URL_ENCODED);
        GCMRegistrar.setRegisteredOnServer(context, false);
        String message = context.getString(R.string.server_unregistered);
        CommonUtilities.displayMessage(context, message);
    } catch (IOException e) {
        // At this point the device is unregistered from GCM, but still
        // registered in the server.
        // We could try to unregister again, but it is not necessary:
        // if the server tries to send a message to the device, it will get
        // a "NotRegistered" error message and should unregister the device.
        String message = context.getString(R.string.server_unregister_error, e.getMessage());
        CommonUtilities.displayMessage(context, message);
    }
}

From source file:Main.java

public static String getMmsAddress(Context context, long messageId) {
    final String[] projection = new String[] { "address", "contact_id", "charset", "type" };
    final String selection = "type=137"; // "type="+ PduHeaders.FROM,

    Uri.Builder builder = MMS_CONTENT_URI.buildUpon();
    builder.appendPath(String.valueOf(messageId)).appendPath("addr");

    Cursor cursor = context.getContentResolver().query(builder.build(), projection, selection, null, null);

    if (cursor != null) {
        try {//from w  w  w.j  av a  2  s  .c om
            if (cursor.moveToFirst()) {
                return cursor.getString(0);
            }
        } finally {
            cursor.close();
        }
    }

    return context.getString(android.R.string.unknownName);
}

From source file:com.ravi.apps.android.newsbytes.sync.NewsSyncAdapter.java

private static void onAccountCreated(Account newAccount, Context context) {
    // Configure the sync.
    NewsSyncAdapter.configurePeriodicSync(context, SYNC_INTERVAL, SYNC_FLEXTIME);

    // Enable periodic sync.
    ContentResolver.setSyncAutomatically(newAccount, context.getString(R.string.content_authority), true);

    // Trigger an immediate sync to get the ball rolling!
    syncImmediately(context);/*from  w ww  .  jav  a  2  s. c o  m*/
}

From source file:com.mobiperf.AccountSelector.java

/**
 * Return the list of account names for users to select
 *//*  w  w w.j av a 2  s . c  o  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:fr.cph.chicago.util.Util.java

public static void trackAction(@NonNull final Context context, final int category, final int action,
        final String label, final int value) {
    new Thread(() -> {
        final Tracker tracker = App.getTracker(context.getApplicationContext());
        tracker.send(new HitBuilders.EventBuilder().setCategory(context.getString(category))
                .setAction(context.getString(action)).setLabel(label).setValue(value).build());
    }).start();//from   w ww.  j ava 2s  . com
}

From source file:net.mandaria.radioreddit.apis.RedditAPI.java

public static String SubmitLink(Context context, RedditAccount account, String title, String url,
        String subreddit, String iden, String captcha) {
    String errorMessage = "";

    try {//from  w ww . j  av a2  s.  c  o  m
        try {
            account.Modhash = updateModHash(context);

            if (account.Modhash == null) {
                errorMessage = context.getString(R.string.error_ThereWasAProblemSubmittingPleaseTryAgain);
                return errorMessage;
            }
        } catch (Exception ex) {
            errorMessage = ex.getMessage();
            return errorMessage;
        }

        String posturl = context.getString(R.string.reddit_submit);

        // post values
        ArrayList<NameValuePair> post_values = new ArrayList<NameValuePair>();

        BasicNameValuePair postTitle = new BasicNameValuePair("title", title);
        post_values.add(postTitle);

        BasicNameValuePair postUrl = new BasicNameValuePair("url", url);
        post_values.add(postUrl);

        BasicNameValuePair sr = new BasicNameValuePair("sr", subreddit);
        post_values.add(sr);

        BasicNameValuePair kind = new BasicNameValuePair("kind", "link");
        post_values.add(kind);

        BasicNameValuePair uh = new BasicNameValuePair("uh", account.Modhash);
        post_values.add(uh);

        if (!iden.equals("") && !captcha.equals("")) {
            BasicNameValuePair postIden = new BasicNameValuePair("iden", iden);
            post_values.add(postIden);

            BasicNameValuePair postCaptcha = new BasicNameValuePair("captcha", captcha);
            post_values.add(postCaptcha);
        }
        // json doesn't work for this call
        //BasicNameValuePair api_type = new BasicNameValuePair("api_type", "json");
        //post_values.add(api_type);

        String outputSubmit = HTTPUtil.post(context, posturl, post_values);

        // returns shitty jquery not json
        if (outputSubmit.equals(""))
            return context.getString(R.string.error_NoContentReturnFromReplyPOST);

        if (outputSubmit.contains("WRONG_PASSWORD"))
            return context.getString(R.string.error_WrongPassword);

        if (outputSubmit.contains("USER_REQUIRED"))
            return context.getString(R.string.error_UserRequired);

        if (outputSubmit.contains("SUBREDDIT_NOEXIST"))
            return context.getString(R.string.error_ThatSubredditDoesNotExist);

        if (outputSubmit.contains("SUBREDDIT_NOTALLOWED"))
            return context.getString(R.string.error_YouAreNotAllowedToPostToThatSubreddit);

        String newId = "";
        String newSubreddit = "";
        Matcher idMatcher = NEW_THREAD_PATTERN.matcher(outputSubmit);
        if (idMatcher.find()) {
            newSubreddit = idMatcher.group(1);
            newId = idMatcher.group(2);
        } else {
            if (outputSubmit.contains("ALREADY_SUB"))
                return context.getString(R.string.error_SorrySomeoneAlreadySubmitted);

            if (outputSubmit.contains("RATELIMIT")) {
                // Try to find the number of minutes using regex
                Matcher rateMatcher = RATELIMIT_RETRY_PATTERN.matcher(outputSubmit);
                if (rateMatcher.find())
                    return rateMatcher.group(1);
                else
                    return context.getString(R.string.error_YouAreTryingToSubmitTooFast);
            }

            if (outputSubmit.contains("BAD_CAPTCHA")) {
                Matcher captchaMatcher = CAPTCHA_PATTERN.matcher(outputSubmit);
                if (captchaMatcher.find())
                    return "CAPTCHA:" + captchaMatcher.group(1);
                else
                    return context.getString(R.string.error_BadCAPTCHATryAgain);
            }

            if (outputSubmit.contains("verify your email"))
                return context.getString(R.string.error_EmailNotVerified);
            // TODO: somehow add link to: http://www.reddit.com/verify?reason=submit
            // could check for this error message on the other end and add a button that opens the link in the browser

            return context.getString(R.string.error_NoIdReturnedByReplyPOST);
        }
        // success!
    } catch (Exception ex) {
        // We fail to submit...
        CustomExceptionHandler ceh = new CustomExceptionHandler(context);
        ceh.sendEmail(ex);

        ex.printStackTrace();

        errorMessage = ex.toString();
    }

    return errorMessage;
}

From source file:fr.cph.chicago.util.Util.java

@NonNull
public static MultiValuedMap<String, String> getFavoritesTrainParams(@NonNull final Context context) {
    final MultiValuedMap<String, String> paramsTrain = new ArrayListValuedHashMap<>();
    final List<Integer> favorites = Preferences.getTrainFavorites(context, App.PREFERENCE_FAVORITES_TRAIN);
    Stream.of(favorites).forEach(
            favorite -> paramsTrain.put(context.getString(R.string.request_map_id), favorite.toString()));
    return paramsTrain;
}

From source file:pj.rozkladWKD.DeviceRegistrar.java

public static void registerWithServer(final Context context, final String deviceRegistrationID) {
    new Thread(new Runnable() {
        public void run() {
            Intent updateUIIntent = new Intent("com.google.ctp.UPDATE_UI");
            try {
                List<NameValuePair> post = new ArrayList<NameValuePair>();
                post.add(new BasicNameValuePair("requestType", "REGISTER_PUSH"));
                post.add(new BasicNameValuePair("deviceId", DeviceIdGenerator.getDeviceId()));
                post.add(new BasicNameValuePair("clientRegistrationId", deviceRegistrationID));
                post.add(new BasicNameValuePair("productId", context.getString(R.string.productId)));

                JSONObject result = HttpClient.SendHttpPost(post);

                if (result == null || result.getString("result") == "ERROR") {
                    updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);

                } else {
                    updateUIIntent.putExtra(STATUS_EXTRA, REGISTERED_STATUS);
                    SharedPreferences settings = Prefs.get(context);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString(Prefs.REGISTRATION_ID, deviceRegistrationID);
                    editor.commit();//  w  w w  .  j a va  2  s .c  o  m
                }

                context.sendBroadcast(updateUIIntent);

            } catch (Exception e) {
                updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
                context.sendBroadcast(updateUIIntent);
            }
        }
    }).start();
}

From source file:pj.rozkladWKD.DeviceRegistrar.java

public static void unregisterWithServer(final Context context, final String deviceRegistrationID) {
    new Thread(new Runnable() {
        public void run() {
            Intent updateUIIntent = new Intent("com.google.ctp.UPDATE_UI");
            try {

                List<NameValuePair> post = new ArrayList<NameValuePair>();
                post.add(new BasicNameValuePair("requestType", "UNREGISTER_PUSH"));
                post.add(new BasicNameValuePair("deviceId", DeviceIdGenerator.getDeviceId()));
                post.add(new BasicNameValuePair("clientRegistrationId", deviceRegistrationID));
                post.add(new BasicNameValuePair("productId", context.getString(R.string.productId)));

                JSONObject result = HttpClient.SendHttpPost(post);
            } catch (Exception e) {
                if (RozkladWKD.DEBUG_LOG) {
                    Log.e("PUSH", e.getMessage(), e);
                }/*from  w ww. j  av a2  s. c o  m*/
            } finally {
                SharedPreferences settings = Prefs.get(context);
                SharedPreferences.Editor editor = settings.edit();
                editor.remove(Prefs.REGISTRATION_ID);
                editor.commit();
                updateUIIntent.putExtra(STATUS_EXTRA, UNREGISTERED_STATUS);
            }

            // Update dialog activity
            context.sendBroadcast(updateUIIntent);
        }
    }).start();
}

From source file:fr.cph.chicago.util.Util.java

@NonNull
public static MultiValuedMap<String, String> getFavoritesBusParams(@NonNull final Context context) {
    final MultiValuedMap<String, String> paramsBus = new ArrayListValuedHashMap<>();
    final List<String> busFavorites = Preferences.getBusFavorites(context, App.PREFERENCE_FAVORITES_BUS);
    Stream.of(busFavorites).map(Util::decodeBusFavorite).forEach(fav -> {
        paramsBus.put(context.getString(R.string.request_rt), fav[0]);
        paramsBus.put(context.getString(R.string.request_stop_id), fav[1]);
    });/*from w  ww . ja v a 2  s .  c  o  m*/
    return paramsBus;
}