Example usage for android.os Bundle getString

List of usage examples for android.os Bundle getString

Introduction

In this page you can find the example usage for android.os Bundle getString.

Prototype

@Nullable
public String getString(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:com.groupme.sdk.util.HttpUtils.java

public static InputStream openStream(HttpClient client, String url, int method, String body, Bundle params,
        Bundle headers) throws HttpResponseException {
    HttpResponse response;// w w  w. j  a  va  2 s  . c om
    InputStream in = null;

    Log.v("HttpUtils", "URL = " + url);

    try {
        switch (method) {
        case METHOD_GET:
            url = url + "?" + encodeParams(params);
            HttpGet get = new HttpGet(url);

            if (headers != null && !headers.isEmpty()) {
                for (String header : headers.keySet()) {
                    get.setHeader(header, headers.getString(header));
                }
            }

            response = client.execute(get);
            break;
        case METHOD_POST:
            if (body != null) {
                url = url + "?" + encodeParams(params);
            }

            HttpPost post = new HttpPost(url);
            Log.d(Constants.LOG_TAG, "URL: " + url);

            if (headers != null && !headers.isEmpty()) {
                for (String header : headers.keySet()) {
                    post.setHeader(header, headers.getString(header));
                }
            }

            if (body == null) {
                List<NameValuePair> pairs = bundleToList(params);
                post.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8));
            } else {
                post.setEntity(new StringEntity(body));
            }

            response = client.execute(post);
            break;
        case METHOD_PUT:
            if (body != null) {
                url = url + "?" + encodeParams(params);
            }

            HttpPut put = new HttpPut(url);

            if (headers != null && !headers.isEmpty()) {
                for (String header : headers.keySet()) {
                    put.setHeader(header, headers.getString(header));
                }
            }

            if (body == null) {
                List<NameValuePair> pairs = bundleToList(params);
                put.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8));
            } else {
                put.setEntity(new StringEntity(body));
            }

            response = client.execute(put);
            break;
        default:
            throw new UnsupportedOperationException("Cannot execute HTTP method: " + method);
        }

        int statusCode = response.getStatusLine().getStatusCode();

        if (statusCode > 400) {
            throw new HttpResponseException(statusCode, read(response.getEntity().getContent()));
        }

        in = response.getEntity().getContent();
    } catch (ClientProtocolException e) {
        Log.e(Constants.LOG_TAG, "Client error: " + e.toString());
    } catch (IOException e) {
        Log.e(Constants.LOG_TAG, "IO error: " + e.toString());
    }

    return in;
}

From source file:Main.java

public static String toString(Intent intent) {
    StringBuilder sb = new StringBuilder();
    sb.append(intent.getAction()).append(" ");

    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Set<String> sets = bundle.keySet();
        for (String key : sets) {
            if (bundle.get(key) instanceof Integer) {
                sb.append(key).append(":").append(bundle.getInt(key)).append("\n");
            } else if (bundle.get(key) instanceof ArrayList) {
                sb.append(key).append(":").append(Arrays.toString(bundle.getIntegerArrayList(key).toArray()))
                        .append("\n");
            } else if (bundle.get(key) instanceof Parcelable) {
                sb.append(key).append(":").append(bundle.getParcelable(key).toString()).append("\n");
            } else {
                sb.append(key).append(":").append(bundle.getString(key)).append("\n");
            }//  w w w . j ava 2  s  .c  o m
        }

    }

    return sb.toString();
}

From source file:cn.bidaround.ytcore.kaixin.KaixinUtil.java

/**
 * ?multi-part??/*from  w  w w . j  a  v  a 2 s . c o  m*/
 * 
 * @param parameters
 *            key-value??
 * @param boundary
 *            ?
 * @return multi-part??
 */
public static String encodePostBody(Bundle parameters, String boundary) {
    if (parameters == null)
        return "";
    StringBuilder sb = new StringBuilder();

    for (String key : parameters.keySet()) {

        //         if (parameters.getByteArray(key) != null) {
        //            continue;
        //         }

        sb.append("Content-Disposition: form-data; name=\"" + key + "\"\r\n\r\n" + parameters.getString(key));
        sb.append("\r\n" + "--" + boundary + "\r\n");
    }

    return sb.toString();
}

From source file:com.zrlh.llkc.funciton.Http_Utility.java

/**
 * Construct a url encoded entity by parameters .
 * /*www .j  a  va2  s . co  m*/
 * @param bundle
 *            :parameters key pairs
 * @return UrlEncodedFormEntity: encoed entity
 */
public static UrlEncodedFormEntity getPostParamters(Bundle bundle) throws Exception {
    if (bundle == null || bundle.isEmpty()) {
        return null;
    }
    try {
        List<NameValuePair> form = new ArrayList<NameValuePair>();
        for (String key : bundle.keySet()) {
            form.add(new BasicNameValuePair(key, bundle.getString(key)));
        }
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, "UTF-8");
        return entity;
    } catch (UnsupportedEncodingException e) {
        throw new UnsupportedEncodingException();
    }
}

From source file:it.scoppelletti.mobilepower.app.AppUtils.java

/**
 * Restituisce il nome del pacchetto di un&rsquo;applicazione.
 * /*from  ww w.ja va2s  .  c  o  m*/
 * @param  ctx        Contesto.
 * @param  onlyIfDemo Indica se restituire il nome del pacchetto solo se
 *                    l&rsquo;applicazione &egrave; una versione di demo.
 * @return            Nome del pacchetto. Se il parametro {@code onlyIfDemo}
 *                    &egrave; impostato, pu&ograve; essere {@code null}.
 */
static String getFullPackageName(Context ctx, boolean onlyIfDemo) {
    String pkgName, value;
    Bundle data;
    ApplicationInfo applInfo;
    PackageManager pkgMgr;

    if (ctx == null) {
        throw new NullPointerException("Argument ctx is null.");
    }

    pkgName = ctx.getPackageName();
    pkgMgr = ctx.getPackageManager();

    try {
        applInfo = pkgMgr.getApplicationInfo(pkgName, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException ex) {
        myLogger.error("Failed to get ApplicationInfo.", ex);
        applInfo = ctx.getApplicationInfo();
    }

    data = applInfo.metaData;
    value = (data != null) ? data.getString(AppUtils.METADATA_FULLPACKAGE) : null;
    if (!StringUtils.isBlank(value)) {
        pkgName = value;
    } else if (onlyIfDemo) {
        return null;
    }

    return pkgName;
}

From source file:com.vidinoti.pixlive.PixLive.java

static void startSDK(final Context c) {

    if (VDARSDKController.getInstance() != null) {
        return;/*from  w  ww.  jav  a  2 s  .  co  m*/
    }

    String storage = c.getApplicationContext().getFilesDir().getAbsolutePath() + "/pixliveSDK";

    String licenseKey = null;

    try {
        ApplicationInfo ai = c.getPackageManager().getApplicationInfo(c.getPackageName(),
                PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        licenseKey = bundle.getString("com.vidinoti.pixlive.LicenseKey");
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    } catch (NullPointerException e) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    }

    if (storage == null || licenseKey == null) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    }

    VDARSDKController.startSDK(c, storage, licenseKey);

    /* Comment out to disable QR code detection */
    VDARSDKController.getInstance().setEnableCodesRecognition(true);

    VDARSDKController.getInstance().setNotificationFactory(new NotificationFactory() {

        @Override
        public Notification createNotification(String title, String message, String notificationID) {

            Intent appIntent = c.getPackageManager().getLaunchIntentForPackage(c.getPackageName());

            appIntent.putExtra("nid", notificationID);
            appIntent.putExtra("remote", false);

            PendingIntent contentIntent = PendingIntent.getActivity(c, 0, appIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            ApplicationInfo ai = c.getApplicationInfo();

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c)
                    .setSmallIcon(ai.icon != 0 ? ai.icon : android.R.drawable.star_big_off)
                    .setContentTitle(title).setContentText(message).setContentIntent(contentIntent)
                    .setAutoCancel(true).setVibrate(new long[] { 100, 200, 200, 400 })
                    .setLights(Color.BLUE, 500, 1500);

            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

            return mBuilder.getNotification();
        }
    });
}

From source file:io.teak.sdk.Session.java

/**
 * Process an Intent and assign new values for launching from a deep link or Teak notification.
 * <p/>//from  w  ww . j a v  a 2s. c om
 * If currentSession was launched via a deep link or notification, and the incoming intent has
 * a new (non null/empty) value. Create a new Session, cloning state from the old one.
 *
 * @param intent Incoming Intent to process.
 */
public static void processIntent(Intent intent, @NonNull AppConfiguration appConfiguration,
        @NonNull DeviceConfiguration deviceConfiguration) {
    if (intent == null)
        return;

    synchronized (currentSessionMutex) {
        // Call getCurrentSession() so the null || Expired logic stays in one place
        getCurrentSession(appConfiguration, deviceConfiguration);

        // Check for launch via deep link
        String intentDataString = intent.getDataString();
        String launchedFromDeepLink = null;
        if (intentDataString != null && !intentDataString.isEmpty()) {
            launchedFromDeepLink = intentDataString;
            if (Teak.isDebug) {
                Log.d(LOG_TAG, "Launch from deep link: " + launchedFromDeepLink);
            }
        }

        // Check for launch via notification
        Bundle bundle = intent.getExtras();
        String launchedFromTeakNotifId = null;
        if (bundle != null) {
            String teakNotifId = bundle.getString("teakNotifId");
            if (teakNotifId != null && !teakNotifId.isEmpty()) {
                launchedFromTeakNotifId = teakNotifId;
                if (Teak.isDebug) {
                    Log.d(LOG_TAG, "Launch from Teak notification: " + launchedFromTeakNotifId);
                }
            }
        }

        // If the current session has a launch from deep link/notification, and there is a new
        // deep link/notification, it's a new session
        if (stringsAreNotNullOrEmptyAndAreDifferent(currentSession.launchedFromDeepLink, launchedFromDeepLink)
                || stringsAreNotNullOrEmptyAndAreDifferent(currentSession.launchedFromTeakNotifId,
                        launchedFromTeakNotifId)) {
            Session oldSession = currentSession;
            currentSession = new Session(oldSession.appConfiguration, oldSession.deviceConfiguration);
            currentSession.userId = oldSession.userId;
            currentSession.attributionChain.addAll(oldSession.attributionChain);

            oldSession.setState(State.Expiring);
            oldSession.setState(State.Expired);
        }

        // Assign attribution
        if (launchedFromDeepLink != null && !launchedFromDeepLink.isEmpty()) {
            currentSession.launchedFromDeepLink = launchedFromDeepLink;
            currentSession.attributionChain.add(launchedFromDeepLink);
        } else if (launchedFromTeakNotifId != null && !launchedFromTeakNotifId.isEmpty()) {
            currentSession.launchedFromTeakNotifId = launchedFromTeakNotifId;
            currentSession.attributionChain.add(launchedFromTeakNotifId);
        }
    }
}

From source file:com.sonyericsson.android.drm.drmlicenseservice.DLSHttpClient.java

private static void addParameters(Bundle parameters, HttpRequestBase request) {
    if (parameters != null && request != null) {
        Bundle headers = parameters.getBundle(Constants.DRM_KEYPARAM_HTTP_HEADERS);
        if (headers != null && headers.size() > 0) {
            for (String headerKey : headers.keySet()) {
                if (headerKey != null && headerKey.length() > 0) {
                    String headerValue = headers.getString(headerKey);
                    if (headerValue != null && headerValue.length() > 0) {
                        request.setHeader(headerKey, headerValue);
                    }//  w w  w. j a  v  a 2s  . c om
                }
            }
        }
    }
}

From source file:ru.appsm.inapphelp.IAHHelpDesk.java

/**
 *
 * Handle push notification.//from w ww. jav  a  2 s  .  c o m
 *
 * @param intent
 * @param context
 */
public static void HandelPushIntentWithContext(Intent intent, Context context) {
    Log.i(TAG, "handle push");
    Bundle extras = intent.getExtras();
    if (extras != null && extras.containsKey("secretkey") && extras.containsKey("userid")
            && extras.containsKey("appkey") && extras.containsKey("appid") && extras.containsKey("email")
            && extras.containsKey("message") && extras.containsKey("title") && extras.containsKey("notId")
            && extras.containsKey("msgId")) {
        JSONObject data = new JSONObject();
        int notId = 1;
        try {
            notId = Integer.parseInt(extras.getString("notId"));
        } catch (NumberFormatException e) {
            notId = 1;
        }
        try {
            data.put("notId", notId);
            data.put("userid", extras.getString("userid"));
            data.put("appid", extras.getString("appid"));
            data.put("appkey", extras.getString("appkey"));
            data.put("secretkey", extras.getString("secretkey"));
            data.put("email", extras.getString("email"));
            data.put("title", extras.getString("title"));
            data.put("message", extras.getString("message"));
            data.put("msgId", extras.getString("msgId"));
            data.put("sound", extras.getString("sound"));
            IAHHelpDesk.BuildNotificationForDataWithContext(data, context);
        } catch (JSONException e) {
            Log.i(TAG, "Fail to parse push data");
        }
    } else {
        Log.i(TAG, "Empty or wrong push intent");
    }
}

From source file:com.permpings.utils.facebook.sdk.Util.java

public static String encodeUrl(Bundle parameters) {
    if (parameters == null) {
        return "";
    }//from   w  w  w .j  a  v a2s. co m

    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (String key : parameters.keySet()) {
        Object parameter = parameters.get(key);
        if (!(parameter instanceof String)) {
            continue;
        }

        if (first)
            first = false;
        else
            sb.append("&");
        try {
            sb.append(URLEncoder.encode(key, HTTP.UTF_8) + "="
                    + URLEncoder.encode(parameters.getString(key), HTTP.UTF_8));
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return sb.toString();
}