List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:com.cbtec.eliademy.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from w w w. j a va2s. com private static void generateNotification(Context context, String message) { int icon = R.drawable.icon; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, Eliademy.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.jamesgiang.aussnowcam.Utils.java
public static void About(Context c) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(c); dialogBuilder.setTitle(R.string.app_name); dialogBuilder.setIcon(R.drawable.icon); TextView textView = new TextView(c); SpannableString s = new SpannableString(c.getString(R.string.about_info)); Linkify.addLinks(s, Linkify.WEB_URLS); textView.setText(s);/*from ww w. j a v a2 s. c o m*/ textView.setGravity(Gravity.CENTER); textView.setMovementMethod(LinkMovementMethod.getInstance()); dialogBuilder.setView(textView); dialogBuilder.show(); }
From source file:Main.java
/** * Tries to pull the Custom Attribute directly from the TextView. * * @param context Activity Context/* ww w. j av a 2s. c o m*/ * @param attrs View Attributes * @param attributeId if -1 returns null. * @return null if attribute is not defined or added to View */ static String pullFontPathFromView(Context context, AttributeSet attrs, int attributeId) { if (attributeId == -1) return null; final String attributeName; try { attributeName = context.getResources().getResourceEntryName(attributeId); } catch (Resources.NotFoundException e) { // invalid attribute ID return null; } final int stringResourceId = attrs.getAttributeResourceValue(null, attributeName, -1); return stringResourceId > 0 ? context.getString(stringResourceId) : attrs.getAttributeValue(null, attributeName); }
From source file:com.scvngr.levelup.core.net.LevelUpRequest.java
/** * Gets the full endpoint URL.//from w w w . ja v a 2 s . c o m * * @param context Application context. * @param apiVersion the version of the API to hit. * @param endpoint the endpoint to hit. * @return the full URL to the endpoint passed. */ @NonNull public static String getFullUrl(@NonNull final Context context, @NonNull final String apiVersion, @NonNull final String endpoint) { return NullUtils.nonNullContract(new Uri.Builder().scheme(context.getString(R.string.levelup_api_scheme)) .encodedAuthority(context.getString(R.string.levelup_api_authority)).encodedPath(apiVersion) .appendEncodedPath(endpoint).build().toString()); }
From source file:fr.free.nrw.commons.Utils.java
/** * Opens Custom Tab Activity with in-app browser for the specified URL. * Launches intent for web URL// w ww . ja v a2s. c om * @param context * @param url */ public static void handleWebUrl(Context context, Uri url) { Timber.d("Launching web url %s", url.toString()); Intent browserIntent = new Intent(Intent.ACTION_VIEW, url); if (browserIntent.resolveActivity(context.getPackageManager()) == null) { Toast toast = Toast.makeText(context, context.getString(R.string.no_web_browser), LENGTH_SHORT); toast.show(); return; } CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(ContextCompat.getColor(context, R.color.primaryColor)); builder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.primaryDarkColor)); builder.setExitAnimations(context, android.R.anim.slide_in_left, android.R.anim.slide_out_right); CustomTabsIntent customTabsIntent = builder.build(); // Clear previous browser tasks, so that back/exit buttons work as intended. customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); customTabsIntent.launchUrl(context, url); }
From source file:org.herrlado.websms.connector.mycoolsms.Connector.java
private static String getStringResourceByName(Context ctx, String aString) { int resId = ctx.getResources().getIdentifier(aString, "string", PACKAGE_NAME); return ctx.getString(resId); }
From source file:com.rocketsingh.biker.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from w ww .j a va2 s .c o m public static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MapActivity.class); notificationIntent.putExtra("fromNotification", "notification"); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; System.out.println("notification====>" + message); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; // notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0x00000000; notification.ledOnMS = 0; notification.ledOffMS = 0; notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WakeLock"); wakeLock.acquire(); wakeLock.release(); }
From source file:Main.java
/** * Tries to pull the Custom Attribute directly from the TextView. * * @param context Activity Context//from www . j a v a2 s . co m * @param attrs View Attributes * @param attributeId if -1 returns null. * @return null if attribute is not defined or added to View */ static String pullFontPathFromView(Context context, AttributeSet attrs, int attributeId) { if (attributeId == -1 || attrs == null) return null; final String attributeName; try { attributeName = context.getResources().getResourceEntryName(attributeId); } catch (Resources.NotFoundException e) { // invalid attribute ID return null; } final int stringResourceId = attrs.getAttributeResourceValue(null, attributeName, -1); return stringResourceId > 0 ? context.getString(stringResourceId) : attrs.getAttributeValue(null, attributeName); }
From source file:com.creationgroundmedia.popularmovies.sync.MovieSyncAdapter.java
public static void syncImmediately(Context context) { Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), bundle); }
From source file:at.ac.uniklu.mobile.sportal.util.Utils.java
/** * Creates an intent to open the app page on facebook if the fb-app is installed, * else opens the page in the browser.//from w w w . j av a 2 s.co m * taken from: http://stackoverflow.com/questions/4810803/open-facebook-page-from-android-app */ public static Intent getOpenFacebookIntent(Context context) { try { context.getPackageManager().getPackageInfo("com.facebook.katana", 0); return new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.credits_facebookpage_appurl))); } catch (Exception e) { return new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.credits_facebookpage_fullurl))); } }