Example usage for android.os Bundle keySet

List of usage examples for android.os Bundle keySet

Introduction

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

Prototype

public Set<String> keySet() 

Source Link

Document

Returns a Set containing the Strings used as keys in this Bundle.

Usage

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

/**
 * Connect to an HTTP URL and return the response as a string.
 *
 * Note that the HTTP method override is used on non-GET requests. (i.e.
 * requests are made as "POST" with method specified in the body).
 *
 * @param url - the resource to open: must be a welformed URL
 * @param method - the HTTP method to use ("GET", "POST", etc.)
 * @param params - the query parameter for the URL (e.g. access_token=foo)
 * @return the URL contents as a String//from ww  w  .j  a  v  a 2  s . c om
 * @throws MalformedURLException - if the URL format is invalid
 * @throws IOException - if a network problem occurs
 */
public static String openUrl(String url, String method, Bundle params)
        throws MalformedURLException, IOException {
    // random string as boundary for multi-part http post
    String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f";
    String endLine = "\r\n";

    OutputStream os;

    if (method.equals("GET")) {
        url = url + "?" + encodeUrl(params);
    }
    Util.logd("Facebook-Util", method + " URL: " + url);
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setRequestProperty("User-Agent",
            System.getProperties().getProperty("http.agent") + " FacebookAndroidSDK");
    if (!method.equals("GET")) {
        Bundle dataparams = new Bundle();
        for (String key : params.keySet()) {
            Object parameter = params.get(key);
            if (parameter instanceof byte[]) {
                dataparams.putByteArray(key, (byte[]) parameter);
            }
        }

        // use method override
        if (!params.containsKey("method")) {
            params.putString("method", method);
        }

        if (params.containsKey("access_token")) {
            String decoded_token = URLDecoder.decode(params.getString("access_token"));
            params.putString("access_token", decoded_token);
        }

        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + strBoundary);
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestProperty("Connection", "Keep-Alive");
        conn.connect();
        os = new BufferedOutputStream(conn.getOutputStream());

        os.write(("--" + strBoundary + endLine).getBytes());
        os.write((encodePostBody(params, strBoundary)).getBytes());
        os.write((endLine + "--" + strBoundary + endLine).getBytes());

        if (!dataparams.isEmpty()) {

            for (String key : dataparams.keySet()) {
                os.write(("Content-Disposition: form-data; filename=\"" + key + "\"" + endLine).getBytes());
                os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes());
                os.write(dataparams.getByteArray(key));
                os.write((endLine + "--" + strBoundary + endLine).getBytes());

            }
        }
        os.flush();
    }

    String response = "";
    try {
        response = read(conn.getInputStream());
    } catch (FileNotFoundException e) {
        // Error Stream contains JSON that we can parse to a FB error
        response = read(conn.getErrorStream());
    }
    return response;
}

From source file:com.pixplicity.wizardpager.wizard.model.AbstractWizardModel.java

public void load(Bundle savedValues) {
    for (String key : savedValues.keySet()) {
        Page page = mRootPageList.findByKey(key);
        page.resetData(savedValues.getBundle(key));
    }/*  www  .ja  v  a  2s  .c om*/
}

From source file:edu.scu.userinterface.MyGcmListenerService.java

/**
 * Called when message is received./*from   w  ww .  jav  a 2s  . c o  m*/
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    Log.d(TAG, "From: " + from);
    for (String key : data.keySet()) {
        Log.d(TAG, key + ": " + data.getString(key));
    }
    //sendNotification(data.getString("data"));
    Intent intent = new Intent(this, VisitorNotification.class);
    intent.putExtra("notification", data);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification).setContentTitle(data.getString("title"))
            .setContentText(data.getString("body")).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.java

/** @return true if intent contained a message to send. */
private boolean sendMessageFromIntent(String method, Intent intent) {
    if (CLICK_ACTION_VALUE.equals(intent.getAction())
            || CLICK_ACTION_VALUE.equals(intent.getStringExtra("click_action"))) {
        Map<String, String> message = new HashMap<>();
        Bundle extras = intent.getExtras();
        for (String key : extras.keySet()) {
            message.put(key, extras.get(key).toString());
        }//  ww  w .  j av a  2  s .co  m
        channel.invokeMethod(method, message);
        return true;
    }
    return false;
}

From source file:com.syncano.gcmsample.MyGcmListenerService.java

/**
 * Called when message is received.//from   w ww.j  av a2s  .co m
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
@Override
public void onMessageReceived(String from, Bundle data) {
    StringBuilder sb = new StringBuilder();
    for (String key : data.keySet()) {
        sb.append(key);
        sb.append(':');
        sb.append(data.get(key).toString());
        sb.append(' ');
    }
    String receivedData = sb.toString();
    Log.d(TAG, "From: " + from);
    Log.d(TAG, "Message: " + receivedData);

    showNotification(receivedData);
}

From source file:org.microg.gms.gcm.SendReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getExtras() == null)
        return;//from   ww  w . ja v a2s.c o  m
    Bundle extras = intent.getExtras();
    Log.d("GmsMcsSendRcvr", "original extras: " + extras);
    for (String key : extras.keySet()) {
        if (key.startsWith("GOOG.") || key.startsWith("GOOGLE.")) {
            extras.remove(key);
        }
    }
    Intent i = new Intent(context, McsService.class);
    i.setAction(ACTION_SEND);
    i.putExtras(extras);
    startWakefulService(context, i);
}

From source file:com.example.gcmandroid.GcmService.java

@Override
public void onMessageReceived(String from, Bundle data) {
    JSONObject jsonObject = new JSONObject();
    Set<String> keys = data.keySet();
    for (String key : keys) {
        try {//from   w  w  w .  ja va2 s. c  o m
            jsonObject.put(key, data.get(key));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    try {
        sendNotification("Received: " + jsonObject.toString(5));
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.demo.push.GcmListener.java

/**
 * Called when message is received.//from   w ww .j  a va 2s. c  o m
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {

    String message = data.getString("text");

    for (String key : data.keySet()) {
        Timber.v(" key " + key + "\n value: " + data.get(key));
    }

    if (pushRecieveListener != null) {
        pushRecieveListener.onPushRecieve();
    }

    sendNotification(message);
}

From source file:com.binil.pushnotification.GcmIntentService.java

@Override
public void onMessageReceived(String from, Bundle extras) {

    Log.i(TAG, "from = " + from);
    for (String key : extras.keySet()) {
        Log.i(TAG, "key = " + key + ", value = " + extras.get(key));
    }/*from   w  ww. j  a v a2  s .  com*/
    sendNotification(extras);
    Log.i(TAG, "Received: " + extras.toString());
}

From source file:com.easyauth.EasyAuth.GCMIntentService.java

@Override
protected void onMessage(Context ctxt, Intent message) {
    Bundle extras = message.getExtras();

    for (String key : extras.keySet()) {
        Log.d(getClass().getSimpleName(), String.format("onMessage: %s=%s", key, extras.getString(key)));
    }/*from   w  ww .ja  va  2 s  .  co m*/

    sendNotification(extras);
}