List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:im.delight.android.commons.Social.java
/** * Displays an application chooser and composes the described text message (SMS) using the selected application * * @param recipientPhone the recipient's phone number or `null` * @param bodyText the body text of the message * @param captionRes a string resource ID for the title of the application chooser's window * @param context a context reference// w w w .j a v a2 s.co m * @throws Exception if there was an error trying to launch the SMS application */ public static void sendSms(final String recipientPhone, final String bodyText, final int captionRes, final Context context) throws Exception { final Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setType(HTTP.PLAIN_TEXT_TYPE); if (recipientPhone != null && recipientPhone.length() > 0) { intent.setData(Uri.parse("smsto:" + recipientPhone)); } else { intent.setData(Uri.parse("sms:")); } intent.putExtra("sms_body", bodyText); intent.putExtra(Intent.EXTRA_TEXT, bodyText); if (context != null) { // offer a selection of all applications that can handle the SMS Intent context.startActivity(Intent.createChooser(intent, context.getString(captionRes))); } }
From source file:fr.gotorennes.AbstractMapActivity.java
public static Location getLocation(Context context, String address) { if ("".equals(address.trim())) { android.location.Location l = LocationUtils.getLocation(context); return l != null ? new Location(l.getLatitude(), l.getLongitude(), context.getString(R.string.positionActuelle)) : null;/*w ww .j a va2 s. c o m*/ } Geocoder geocoder = new Geocoder(context); try { List<Address> addresses = geocoder.getFromLocationName(address + ",35 ille et vilaine", 1); if (addresses != null && !addresses.isEmpty()) { Address foundAddress = addresses.get(0); return new Location(foundAddress.getLatitude(), foundAddress.getLongitude(), foundAddress.getAddressLine(0)); } } catch (Exception ex) { Log.e("GoToRennes", ex.getMessage()); } return null; }
From source file:realizer.com.schoolgenieparent.ServerUtilities.java
/** * Unregister this account/device pair within the server. *//* w w w.j av a 2 s .co m*/ static void unregister(final Context context, final String regId) { Log.i(Config.TAG, "unregistering device (regId = " + regId + ")"); //String serverUrl = Config.URL + "/deregisterStudentDevice/" + studentID + "/" + regId; // Map<String, String> params = new HashMap<String, String>(); //params.put("regId", regId); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ctx); String did = sharedpreferences.getString("DWEVICEID", ""); String userid = sharedpreferences.getString("UidName", ""); String accesstoken = sharedpreferences.getString("AccessToken", ""); try { postUnregister(userid, did, accesstoken); //GCMRegistrar.setRegisteredOnServer(context, false); String message = context.getString(R.string.server_unregistered); Config.displayMessage(context, message); } catch (Exception 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()); Config.displayMessage(context, message); } }
From source file:com.ofalvai.bpinfo.util.Utils.java
public static String routeTypeToString(@NonNull Context context, @NonNull RouteType routeType) { int resourceId; switch (routeType) { case BUS:/*from w ww . j av a 2 s.c om*/ resourceId = R.string.route_bus; break; case FERRY: resourceId = R.string.route_ferry; break; case RAIL: resourceId = R.string.route_rail; break; case TRAM: resourceId = R.string.route_tram; break; case TROLLEYBUS: resourceId = R.string.route_trolleybus; break; case SUBWAY: resourceId = R.string.route_subway; break; case _OTHER_: resourceId = R.string.route_other; break; default: resourceId = R.string.route_other; } return context.getString(resourceId); }
From source file:com.dnielfe.manager.utils.SimpleUtils.java
public static void openFile(final Context context, final File target) { final String mime = MimeTypes.getMimeType(target); final Intent i = new Intent(Intent.ACTION_VIEW); if (mime != null) { i.setDataAndType(Uri.fromFile(target), mime); } else {// w w w. j a v a2 s .c o m i.setDataAndType(Uri.fromFile(target), "*/*"); } if (context.getPackageManager().queryIntentActivities(i, 0).isEmpty()) { Toast.makeText(context, R.string.cantopenfile, Toast.LENGTH_SHORT).show(); return; } try { context.startActivity(i); } catch (Exception e) { Toast.makeText(context, context.getString(R.string.cantopenfile) + e.getMessage(), Toast.LENGTH_SHORT) .show(); } }
From source file:realizer.com.schoolgenieparent.ServerUtilities.java
/** * Register this account/device pair within the server. * * @return whether the registration succeeded or not. *//* www. j a v a 2 s.c o m*/ static boolean register(final Context context, final String regId, final String empID) { //Log.i(TAG, "registering device (regId = " + regId + ")"); ctx = context; long backoff = BACKOFF_MILLI_SECONDS + random.nextInt(1000); // Once GCM returns a registration id, we need to register it in the // demo server. As the server might be down, we will retry it a couple // times. for (int i = 1; i <= MAX_ATTEMPTS; i++) { Log.d(Config.TAG, "Attempt #" + i + " to register"); try { /*displayMessage(context, context.getString( R.string.server_registering, i, MAX_ATTEMPTS));*/ post(regId, empID); GCMRegistrar.setRegisteredOnServer(context, true); String message = context.getString(R.string.server_registered); Config.displayMessage(context, message); return true; } catch (Exception e) { // Here we are simplifying and retrying on any error; in a real // application, it should retry only on unrecoverable errors // (like HTTP error code 503). Log.e(Config.TAG, "Failed to register on attempt " + i, e); if (i == MAX_ATTEMPTS) { break; } try { Log.d(Config.TAG, "Sleeping for " + backoff + " ms before retry"); Thread.sleep(backoff); } catch (InterruptedException e1) { // Activity finished before we complete - exit. Log.d(Config.TAG, "Thread interrupted: abort remaining retries!"); Thread.currentThread().interrupt(); return false; } // increase backoff exponentially backoff *= 2; } } String message = context.getString(R.string.server_register_error, MAX_ATTEMPTS); Config.displayMessage(context, message); return false; }
From source file:com.devandroid.tkuautowifi.WifiClient.java
public static void logout(final Context context, final LogoutCallback callback) { final String url = "http://163.13.8.254/cgi-bin/ace_web_auth.cgi?logout"; mClient.get(url, new AsyncHttpResponseHandler() { @Override/*from www . j a va 2 s . c om*/ public void onSuccess(int statusCode, String content) { super.onSuccess(statusCode, content); if (statusCode == 200) { if (content.contains("login.php")) { if (callback != null) { callback.onSuccess(); } } else { if (callback != null) { callback.onFailure(context.getString(R.string.logout_error)); } } } else { if (callback != null) { callback.onFailure(context.getString(R.string.logout_error)); } } } @Override public void onFailure(Throwable error, String content) { super.onFailure(error, content); if (callback != null) { callback.onFailure(context.getString(R.string.logout_error)); } } }); }
From source file:com.wellsandwhistles.android.redditsp.fragments.CommentPropertiesDialog.java
@Override protected String getTitle(Context context) { return context.getString(R.string.props_comment_title); }
From source file:com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter.java
/** * Set up the sync to run at periodic intervals. * * @param context/*from w w w.j a v a 2 s . c o m*/ * current application environment context * @param syncInterval * how often to sync in seconds * @param flexTime * how many seconds can it run before syncInterval (inexact timer for versions greater * than KITKAT */ public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); 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).build(); ContentResolver.requestSync(request); } else { ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval); } }
From source file:com.ryan.ryanreader.fragments.PostPropertiesDialog.java
@Override protected String getTitle(Context context) { return context.getString(R.string.props_post_title); }