Example usage for android.os Bundle get

List of usage examples for android.os Bundle get

Introduction

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

Prototype

@Nullable
public Object get(String key) 

Source Link

Document

Returns the entry with the given key as an object.

Usage

From source file:com.kalis.cloudmessaging.MyGcmListenerService.java

/**
 * Called when message is received.//from www .ja  v a 2  s  .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().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    String message = data.get("price").toString();
    Log.d(TAG, "From: " + from);
    Log.d(TAG, "Message: " + message);

    // [START_EXCLUDE]
    /**
     * Production applications would usually process the message here.
     * Eg: - Syncing with server.
     *     - Store message in local database.
     *     - Update UI.
     */

    /**
     * In some cases it may be useful to show a notification indicating to the user
     * that a message was received.
     */
    sendNotification(message);
    // [END_EXCLUDE]
}

From source file:barcamp.com.facebook.android.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/* ww  w. j ava 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);
    }
    Log.d("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()) {
            if (params.get(key) instanceof byte[]) {
                //if (params.getByteArray(key) != null) {
                dataparams.putByteArray(key, params.getByteArray(key));
            }
        }

        // 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.facebook.android.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/*w ww .j  av  a  2s. c o  m*/
 * @throws MalformedURLException - if the URL format is invalid
 * @throws IOException - if a network problem occurs
 */
@Deprecated
public static String openUrl(String url, String method, Bundle params) throws 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);
    }
    Utility.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());

        try {
            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();
        } finally {
            os.close();
        }
    }

    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:SMSBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (SMS_RECEIVED.equals(intent.getAction())) {
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            Object[] pdus = (Object[]) bundle.get("pdus");
            String format = bundle.getString("format");
            final SmsMessage[] messages = new SmsMessage[pdus.length];
            for (int i = 0; i < pdus.length; i++) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], format);
                } else {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                }// ww  w .  j ava  2  s .  c  om
                Toast.makeText(context, messages[0].getMessageBody(), Toast.LENGTH_SHORT).show();
            }
        }
    }
}

From source file:com.CBook.CB.cloudbook.GCMBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();

    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);
    }/*from w  w w. j  av  a 2  s.  c o  m*/

    ComponentName comp = new ComponentName(context.getPackageName(), GCMIntentService.class.getName());
    startWakefulService(context, intent.setComponent(comp));
    setResultCode(Activity.RESULT_OK);

}

From source file:com.microsoft.aad.adal.example.userappwithbroker.ResultFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_result, container, false);

    mTextView = (TextView) view.findViewById(R.id.txt_result);
    final Bundle bundle = getArguments();
    final String accessToken = (String) bundle.get(ACCESS_TOKEN);
    final String idToken = (String) bundle.get(ID_TOKEN);
    final String displayable = (String) bundle.get(DISPLAYABLE);

    mTextView.setText(ACCESS_TOKEN + ": " + accessToken + '\n' + ID_TOKEN + ": " + idToken + '\n' + DISPLAYABLE
            + ": " + displayable);
    mTextView.setMovementMethod(new ScrollingMovementMethod());
    return view;//  w  ww.ja v a  2s . c  o  m
}

From source file:com.microsoft.aad.adal.example.userappwithbroker.LogFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_log, container, false);

    mTextView = (TextView) view.findViewById(R.id.txt_log);
    final Bundle bundle = getArguments();
    final String logs = (String) bundle.get(LOG_MSG);

    mTextView.setText(logs);//from  w w w. j  av a 2 s . c o  m
    mTextView.setMovementMethod(new ScrollingMovementMethod());

    mClearLogButton = (Button) view.findViewById(R.id.btn_clearLogs);
    mClearLogButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mTextView.setText("");
            ((ADALSampleApp) getActivity().getApplication()).clearLogs();
        }
    });
    return view;
}

From source file:com.microsoft.identity.client.testapp.LogFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_log, container, false);

    mTextView = (TextView) view.findViewById(R.id.txt_log);
    final Bundle bundle = getArguments();
    final String logs = (String) bundle.get(LOG_MSG);

    mTextView.setText(logs);/*ww w .j  av  a2  s  .com*/
    mTextView.setMovementMethod(new ScrollingMovementMethod());

    mClearLogButton = (Button) view.findViewById(R.id.btn_clearLogs);
    mClearLogButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mTextView.setText("");
            ((MsalSampleApp) getActivity().getApplication()).clearLogs();
        }
    });
    return view;
}

From source file:android_network.hetnet.vpn_service.Util.java

public static void logBundle(Bundle data) {
    if (data != null) {
        Set<String> keys = data.keySet();
        StringBuilder stringBuilder = new StringBuilder();
        for (String key : keys) {
            Object value = data.get(key);
            stringBuilder.append(key).append("=").append(value)
                    .append(value == null ? "" : " (" + value.getClass().getSimpleName() + ")").append("\r\n");
        }/*ww  w .  j  a va2s  .  c  o  m*/
        Log.d(TAG, stringBuilder.toString());
    }
}

From source file:in.ceeq.receivers.MobileMessagesReceiver.java

/**
 * Sms commands receiver commands allowed Siren, Ring, Now, Calls,
 *///from  ww  w  . j a  v  a 2 s  . c o m
@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();

    Object messages[] = (Object[]) bundle.get("pdus");
    SmsMessage smsMessage[] = new SmsMessage[messages.length];
    for (int n = 0; n < messages.length; n++) {
        smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
    }

    String messageText = smsMessage[0].getMessageBody().toString().toUpperCase();
    String senderAddress = smsMessage[0].getOriginatingAddress();
    Utils.setStringPrefs(context, Utils.SENDER_ADDRESS, senderAddress);
    Intent sendCommand = new Intent(context, CommandService.class);
    if (messageText.contains("CEEQ") && messageText.contains(Utils.getStringPrefs(context, Utils.PIN_NUMBER))) {
        if (messageText.contains("ALARM")) {
            sendCommand.putExtra(CommandService.ACTION, CommandService.SIREN_ON);
        } else if (messageText.contains("RING")) {
            sendCommand.putExtra(CommandService.ACTION, CommandService.RINGER_ON);
        } else if (messageText.contains("ERASE")) {
            sendCommand.putExtra(CommandService.ACTION, CommandService.WIPE);
        } else if (messageText.contains("NOW")) {
            sendCommand.putExtra(CommandService.ACTION,
                    CommandService.GET_LOCATION_FOR_CURRENT_DETAILS_MESSAGE);
        } else if (messageText.contains("CALLS")) {
            sendCommand.putExtra(CommandService.ACTION, CommandService.SEND_CALLS_DETAILS_MESSAGE);
        } else if (messageText.contains("SPY")) {
            sendCommand.putExtra(CommandService.ACTION, CommandService.ENABLE_TRACKER);
        } else if (messageText.contains("LOCATE")) {
            sendCommand.putExtra(CommandService.ACTION, CommandService.GET_LOCATION_FOR_MESSAGE);
        }
    } else
        sendCommand.putExtra(CommandService.ACTION, CommandService.SEND_PIN_FAIL_MESSAGE);

    startWakefulService(context, sendCommand);
    setResultCode(Activity.RESULT_OK);
}