List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:com.ncu.sdroidagent.ServerUtilities.java
/** * Register this account/device pair within the server. * *//* w w w . j a va 2 s.c o m*/ public static void register(final Context context, String name, String email, final String regId) { Log.i(TAG, "registering device (regId = " + regId + ")"); String serverUrl = SERVER_URL + "/SDroid/RegisterServlet.do"; Map<String, String> params = new HashMap<String, String>(); params.put("regId", regId); params.put("name", name); params.put("email", email); try { post(serverUrl, params); GCMRegistrar.setRegisteredOnServer(context, true); String message = context.getString(R.string.server_registered); CommonUtilities.displayMessage(context, message); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.yojiokisoft.japanesecalc.MyUncaughtExceptionHandler.java
/** * ??????./*from w ww. jav a 2s . c om*/ * * @param activityContext ??Activity?Context????? * @param ex */ public static void sendBugReport(Context activityContext, Throwable ex) { try { MyLog.writeStackTrace(MyConst.getCaughtBugFilePath(), ex); } catch (FileNotFoundException e) { e.printStackTrace(); } sBugReportFile = new File(MyConst.getCaughtBugFilePath()); if (sBugReportFile == null || !sBugReportFile.exists()) { return; } setVersionName(); MyDialog.Builder.newInstance(activityContext).setTitle(activityContext.getString(R.string.err_dialog_title)) .setMessage(activityContext.getString(R.string.err_dialog_msg2)) .setPositiveLabel(activityContext.getString(R.string.send)) .setPositiveClickListener(mBugDialogOkClicked) .setNegativeLabel(activityContext.getString(R.string.cancel)) .setNegativeClickListener(mBugDialogCancelClicked).show(); }
From source file:com.libframework.annotation.util.OtherUtils.java
/** * @param context if null, use the default format * (Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 %sSafari/534.30). * @return/* w w w .j a va 2 s . c o m*/ */ public static String getUserAgent(Context context) { String webUserAgent = null; if (context != null) { try { Class<?> sysResCls = Class.forName("com.android.internal.R$string"); Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent"); Integer resId = (Integer) webUserAgentField.get(null); webUserAgent = context.getString(resId); } catch (Throwable ignored) { } } if (TextUtils.isEmpty(webUserAgent)) { webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1"; } Locale locale = Locale.getDefault(); StringBuffer buffer = new StringBuffer(); // Add version final String version = Build.VERSION.RELEASE; if (version.length() > 0) { buffer.append(version); } else { // default to "1.0" buffer.append("1.0"); } buffer.append("; "); final String language = locale.getLanguage(); if (language != null) { buffer.append(language.toLowerCase(Locale.getDefault())); final String country = locale.getCountry(); if (country != null) { buffer.append("-"); buffer.append(country.toLowerCase(Locale.getDefault())); } } else { // default to "en" buffer.append("en"); } // add the model for the release build if ("REL".equals(Build.VERSION.CODENAME)) { final String model = Build.MODEL; if (model.length() > 0) { buffer.append("; "); buffer.append(model); } } final String id = Build.ID; if (id.length() > 0) { buffer.append(" Build/"); buffer.append(id); } return String.format(webUserAgent, buffer, "Mobile "); }
From source file:com.ddiiyy.xydz.xutils.util.OtherUtils.java
/** * @param context if null, use the default format * (Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 %sSafari/534.30). * @return/*from ww w. ja va 2 s .c o m*/ */ @SuppressLint("DefaultLocale") @SuppressWarnings("rawtypes") public static String getUserAgent(Context context) { String webUserAgent = null; if (context != null) { try { Class sysResCls = Class.forName("com.android.internal.R$string"); Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent"); Integer resId = (Integer) webUserAgentField.get(null); webUserAgent = context.getString(resId); } catch (Throwable ignored) { } } if (TextUtils.isEmpty(webUserAgent)) { webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1"; } Locale locale = Locale.getDefault(); StringBuffer buffer = new StringBuffer(); // Add version final String version = Build.VERSION.RELEASE; if (version.length() > 0) { buffer.append(version); } else { // default to "1.0" buffer.append("1.0"); } buffer.append("; "); final String language = locale.getLanguage(); if (language != null) { buffer.append(language.toLowerCase()); final String country = locale.getCountry(); if (country != null) { buffer.append("-"); buffer.append(country.toLowerCase()); } } else { // default to "en" buffer.append("en"); } // add the model for the release build if ("REL".equals(Build.VERSION.CODENAME)) { final String model = Build.MODEL; if (model.length() > 0) { buffer.append("; "); buffer.append(model); } } final String id = Build.ID; if (id.length() > 0) { buffer.append(" Build/"); buffer.append(id); } return String.format(webUserAgent, buffer, "Mobile "); }
From source file:com.rsegismont.androlife.core.utils.AndrolifeUtils.java
public static String getDisplayDate(Context context, SimpleDateFormat format, long date) { switch (SdkUtils.getDiffDate(date)) { case 0://w w w . j a va 2 s. c o m return context.getString(R.string.androlife_dates_today); case 1: return context.getString(R.string.androlife_dates_tommorow); default: return format.format(new Date(date)); } }
From source file:com.miz.apis.trakt.Trakt.java
public static String getApiKey(Context context) { String key = context.getString(R.string.trakt_api_key); if (TextUtils.isEmpty(key) || key.equals("add_your_own")) throw new RuntimeException("You need to add a Trakt API key!"); return key;// w w w .ja v a 2 s .c o m }
From source file:it.feio.android.omninotes.utils.StorageHelper.java
public static boolean deleteExternalStoragePrivateFile(Context mContext, String name) { boolean res = false; // Checks for external storage availability if (!checkStorage()) { Toast.makeText(mContext, mContext.getString(R.string.storage_not_available), Toast.LENGTH_SHORT).show(); return false; }// w ww . j av a 2s. com File file = new File(mContext.getExternalFilesDir(null), name); file.delete(); return true; }
From source file:com.lidroid.xutils.utils.OtherUtils.java
/** * @param context if null, use the default format * (Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 %sSafari/534.30). * @return//from www . j av a2 s . c om */ @SuppressLint("DefaultLocale") public static String getUserAgent(Context context) { String webUserAgent = null; if (context != null) { try { Class<?> sysResCls = Class.forName("com.android.internal.R$string"); Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent"); Integer resId = (Integer) webUserAgentField.get(null); webUserAgent = context.getString(resId); } catch (Throwable ignored) { } } if (TextUtils.isEmpty(webUserAgent)) { webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1"; } Locale locale = Locale.getDefault(); StringBuffer buffer = new StringBuffer(); // Add version final String version = Build.VERSION.RELEASE; if (version.length() > 0) { buffer.append(version); } else { // default to "1.0" buffer.append("1.0"); } buffer.append("; "); final String language = locale.getLanguage(); if (language != null) { buffer.append(language.toLowerCase()); final String country = locale.getCountry(); if (country != null) { buffer.append("-"); buffer.append(country.toLowerCase()); } } else { // default to "en" buffer.append("en"); } // add the model for the release build if ("REL".equals(Build.VERSION.CODENAME)) { final String model = Build.MODEL; if (model.length() > 0) { buffer.append("; "); buffer.append(model); } } final String id = Build.ID; if (id.length() > 0) { buffer.append(" Build/"); buffer.append(id); } return String.format(webUserAgent, buffer, "Mobile "); }
From source file:com.ruint.core.utils.OtherUtils.java
/** * @param context/* w w w.j av a 2s . c om*/ * if null, use the default format (Mozilla/5.0 (Linux; U; Android * %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 * %sSafari/534.30). * @return */ @SuppressWarnings("rawtypes") public static String getUserAgent(Context context) { String webUserAgent = null; if (context != null) { try { Class sysResCls = Class.forName("com.android.internal.R$string"); Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent"); Integer resId = (Integer) webUserAgentField.get(null); webUserAgent = context.getString(resId); } catch (Throwable ignored) { } } if (TextUtils.isEmpty(webUserAgent)) { webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1"; } Locale locale = Locale.getDefault(); StringBuffer buffer = new StringBuffer(); // Add version final String version = Build.VERSION.RELEASE; if (version.length() > 0) { buffer.append(version); } else { // default to "1.0" buffer.append("1.0"); } buffer.append("; "); final String language = locale.getLanguage(); if (language != null) { buffer.append(language.toLowerCase()); final String country = locale.getCountry(); if (country != null) { buffer.append("-"); buffer.append(country.toLowerCase()); } } else { // default to "en" buffer.append("en"); } // add the model for the release build if ("REL".equals(Build.VERSION.CODENAME)) { final String model = Build.MODEL; if (model.length() > 0) { buffer.append("; "); buffer.append(model); } } final String id = Build.ID; if (id.length() > 0) { buffer.append(" Build/"); buffer.append(id); } return String.format(webUserAgent, buffer, "Mobile "); }
From source file:com.grarak.romswitcher.Utils.Utils.java
private static void checkOldPass(Context context) { if (mPassfile.exists()) { String oldPass = ""; try {//from w w w. j a va2 s . c o m oldPass = Utils.readLine(PASS_FILE); } catch (IOException e) { e.printStackTrace(); } if (mOldPassword.getText().toString().trim().equals(oldPass)) { checkNewPass(context); } else { Utils.toast(context, context.getString(R.string.oldpasswrong), 0); setupPassword(context); } } else { checkNewPass(context); } }