List of usage examples for android.os Bundle getString
@Nullable
public String getString(@Nullable String key)
From source file:com.onesignal.NotificationBundleProcessor.java
private static void saveNotification(Context context, Bundle bundle, boolean opened, int notificationId) { try {/*from w ww .j av a 2 s .c o m*/ JSONObject customJSON = new JSONObject(bundle.getString("custom")); OneSignalDbHelper dbHelper = new OneSignalDbHelper(context); SQLiteDatabase writableDb = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(NotificationTable.COLUMN_NAME_NOTIFICATION_ID, customJSON.getString("i")); if (bundle.containsKey("grp")) values.put(NotificationTable.COLUMN_NAME_GROUP_ID, bundle.getString("grp")); values.put(NotificationTable.COLUMN_NAME_OPENED, opened ? 1 : 0); if (!opened) values.put(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, notificationId); if (bundle.containsKey("title")) values.put(NotificationTable.COLUMN_NAME_TITLE, bundle.getString("title")); values.put(NotificationTable.COLUMN_NAME_MESSAGE, bundle.getString("alert")); values.put(NotificationTable.COLUMN_NAME_FULL_DATA, bundleAsJSONObject(bundle).toString()); writableDb.insert(NotificationTable.TABLE_NAME, null, values); // Clean up old records that have been dismissed or opened already after 1 week. writableDb.delete(NotificationTable.TABLE_NAME, NotificationTable.COLUMN_NAME_CREATED_TIME + " < " + ((System.currentTimeMillis() / 1000) - 604800) + " AND " + "(" + NotificationTable.COLUMN_NAME_DISMISSED + " = 1 OR " + NotificationTable.COLUMN_NAME_OPENED + " = 1" + ")", null); writableDb.close(); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.google.android.apps.muzei.api.Artwork.java
/** * Deserializes an artwork object from a {@link Bundle}. *///from ww w . j a v a2s. com public static Artwork fromBundle(Bundle bundle) { Builder builder = new Builder().title(bundle.getString(KEY_TITLE)).byline(bundle.getString(KEY_BYLINE)) .token(bundle.getString(KEY_TOKEN)); String imageUri = bundle.getString(KEY_IMAGE_URI); if (!TextUtils.isEmpty(imageUri)) { builder.imageUri(Uri.parse(imageUri)); } try { String viewIntent = bundle.getString(KEY_VIEW_INTENT); if (!TextUtils.isEmpty(viewIntent)) { builder.viewIntent(Intent.parseUri(viewIntent, Intent.URI_INTENT_SCHEME)); } } catch (URISyntaxException ignored) { } return builder.build(); }
From source file:com.onesignal.NotificationBundleProcessor.java
private static void prepareBundle(Bundle gcmBundle) { if (gcmBundle.containsKey("o")) { try {// ww w . j av a 2 s .c o m JSONObject customJSON = new JSONObject(gcmBundle.getString("custom")); JSONObject additionalDataJSON; if (customJSON.has("a")) additionalDataJSON = customJSON.getJSONObject("a"); else additionalDataJSON = new JSONObject(); JSONArray buttons = new JSONArray(gcmBundle.getString("o")); gcmBundle.remove("o"); for (int i = 0; i < buttons.length(); i++) { JSONObject button = buttons.getJSONObject(i); String buttonText = button.getString("n"); button.remove("n"); String buttonId; if (button.has("i")) { buttonId = button.getString("i"); button.remove("i"); } else buttonId = buttonText; button.put("id", buttonId); button.put("text", buttonText); if (button.has("p")) { button.put("icon", button.getString("p")); button.remove("p"); } } additionalDataJSON.put("actionButtons", buttons); additionalDataJSON.put("actionSelected", DEFAULT_ACTION); if (!customJSON.has("a")) customJSON.put("a", additionalDataJSON); gcmBundle.putString("custom", customJSON.toString()); } catch (JSONException e) { e.printStackTrace(); } } }
From source file:org.linkdroid.PostJob.java
private static boolean shouldDoHmac(Bundle webhook) { return webhook.containsKey(WebhookColumns.SECRET) && !TextUtils.isEmpty(webhook.getString(WebhookColumns.SECRET)); }
From source file:Main.java
public static String encodeUrl(Bundle parameters) { if (parameters == null) return ""; StringBuilder sb = new StringBuilder(); boolean first = true; for (String key : parameters.keySet()) { if (first) first = false;/*from w w w . ja v a2 s. c o m*/ else sb.append("&"); sb.append(key + "=" + parameters.getString(key)); } return sb.toString(); }
From source file:Main.java
@SuppressWarnings("deprecation") public static String encodeUrl(Bundle parameters) { if (parameters == null) { return ""; }//from w w w. j a v a 2 s. c o m StringBuilder sb = new StringBuilder(); boolean first = true; for (String key : parameters.keySet()) { if (first) first = false; else sb.append("&"); if (parameters.getString(key) != null) { sb.append(URLEncoder.encode(key) + "=" + URLEncoder.encode(parameters.getString(key))); } } return sb.toString(); }
From source file:Main.java
public static String getAppKey(Context context) { Bundle metaData = null; String appKey = null;/*from ww w . ja v a 2s .co m*/ try { ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); if (null != ai) metaData = ai.metaData; if (null != metaData) { appKey = metaData.getString(KEY_APP_KEY); if ((null == appKey) || appKey.length() != 24) { appKey = null; } } } catch (PackageManager.NameNotFoundException e) { } return appKey; }
From source file:Main.java
/** * Store the exif attributes in the passed image file using the TAGS stored in the passed bundle * * @param filepath/*www. j a v a2 s. c o m*/ * @param bundle * @return true if success */ public static boolean saveAttributes(final String filepath, Bundle bundle) { ExifInterface exif; try { exif = new ExifInterface(filepath); } catch (IOException e) { e.printStackTrace(); return false; } for (String tag : EXIF_TAGS) { if (bundle.containsKey(tag)) { exif.setAttribute(tag, bundle.getString(tag)); } } try { exif.saveAttributes(); } catch (IOException e) { e.printStackTrace(); return false; } return true; }
From source file:com.owncloud.android.network.OwnCloudClientUtils.java
public static WebdavClient createOwnCloudClient(Account account, Context appContext, Activity currentActivity) throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException { Uri uri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account)); AccountManager am = AccountManager.get(appContext); boolean isOauth2 = am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2) != null; // TODO avoid calling to getUserData here boolean isSamlSso = am.getUserData(account, AccountAuthenticator.KEY_SUPPORTS_SAML_WEB_SSO) != null; WebdavClient client = createOwnCloudClient(uri, appContext, !isSamlSso); if (isOauth2) { // TODO avoid a call to getUserData here AccountManagerFuture<Bundle> future = am.getAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN, null, currentActivity, null, null); Bundle result = future.getResult(); String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN); if (accessToken == null) throw new AuthenticatorException("WTF!"); client.setBearerCredentials(accessToken); // TODO not assume that the access token is a bearer token } else if (isSamlSso) { // TODO avoid a call to getUserData here AccountManagerFuture<Bundle> future = am.getAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE, null, currentActivity, null, null);//from w w w. j a v a 2 s . c o m Bundle result = future.getResult(); String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN); if (accessToken == null) throw new AuthenticatorException("WTF!"); client.setSsoSessionCookie(accessToken); } else { String username = account.name.substring(0, account.name.lastIndexOf('@')); //String password = am.getPassword(account); //String password = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD, false); AccountManagerFuture<Bundle> future = am.getAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD, null, currentActivity, null, null); Bundle result = future.getResult(); String password = result.getString(AccountManager.KEY_AUTHTOKEN); client.setBasicCredentials(username, password); } return client; }
From source file:Main.java
public static String getAppKey(Context context) { Bundle metaData = null; String appKey = null;// w w w . ja va2 s .com try { ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); if (null != ai) metaData = ai.metaData; if (null != metaData) { appKey = metaData.getString(KEY_APP_KEY); if ((null == appKey) || appKey.length() != 24) { appKey = null; } } } catch (NameNotFoundException e) { } return appKey; }