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.nononsenseapps.billing.IabHelper.java

int getResponseCodeFromBundle(Bundle b) {
    if (b == null) {
        logDebug("Bundle with null response code, assuming OK (known issue)");
        return BILLING_RESPONSE_RESULT_OK;
    }/*from   w ww  . java2  s .c om*/
    Object o = b.get(RESPONSE_CODE);
    if (o == null) {
        logDebug("Bundle with null response code, assuming OK (known issue)");
        return BILLING_RESPONSE_RESULT_OK;
    } else if (o instanceof Integer)
        return ((Integer) o).intValue();
    else if (o instanceof Long)
        return (int) ((Long) o).longValue();
    else {
        logError("Unexpected type for bundle response code.");
        logError(o.getClass().getName());
        throw new RuntimeException("Unexpected type for bundle response code: " + o.getClass().getName());
    }
}

From source file:com.ashish.msngr.GCMNotificationIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification("Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

            for (int i = 0; i < 3; i++) {
                Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime());
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                }//from  ww  w . java2 s. c om

            }
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());

            sendNotification("" + extras.get(Config.MESSAGE_KEY));
            RegisterActivity.msg = (String) extras.get(Config.MESSAGE_KEY);
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    GcmBroadcastReceiver.completeWakefulIntent(intent);
    //Intent i = new Intent(this,RegisterActivity.class);
    //i.putExtra("msg",msg);
    //startActivity(i);
}

From source file:gowtham.com.desknote.MyListener.java

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);

    // If user has disabled notifications, then skip
    if (!pref.getBoolean("send_notifications", false))
        return;/*from   w  ww. j a va  2  s.c om*/

    // Look for our device
    Set<String> emptySet = new HashSet<String>();
    Collection<String> addresses = pref.getStringSet("desktop_address", emptySet);
    Log.i(MainActivity.TAG, "Connected devices " + connectedDevices);
    Collection<String> connectedAddresses = getConnectedAddresses(addresses, connectedDevices);

    Notification mNotification = sbn.getNotification();

    // Can't do much if we get a null!
    if (mNotification == null)
        return;

    Bundle extras = mNotification.extras;

    String packageName = sbn.getPackageName();
    String title = extras.getString(Notification.EXTRA_TITLE);
    String text = extras.getString(Notification.EXTRA_TEXT);
    String subText = extras.getString(Notification.EXTRA_SUB_TEXT);
    Integer smallIconID = extras.getInt(Notification.EXTRA_SMALL_ICON);
    String icon = "null";
    if (pref.getBoolean("include_images", false)) {
        if (extras.getParcelable(Notification.EXTRA_LARGE_ICON) != null) {
            Bitmap b = Bitmap.class.cast(extras.getParcelable(Notification.EXTRA_LARGE_ICON));
            icon = bitmap2Base64(b);
        } else {
            icon = getIcon(packageName, smallIconID);
        }
    }

    Map<String, String> extrasMap = new HashMap<String, String>();
    for (String key : extras.keySet()) {
        extrasMap.put(key, String.valueOf(extras.get(key)));
    }

    Log.e(MainActivity.TAG, "Got a new notification " + title + " " + mNotification.hashCode());

    Message msg = new Message(title, text, subText, icon, mNotification.toString(), extrasMap, packageName);
    NotificationTransmitter tx = new NotificationTransmitter();

    Log.e(MainActivity.TAG, "Sending bluetooth message");
    tx.transmit(connectedAddresses, msg);
}

From source file:uk.ac.ucl.excites.sapelli.relay.BackgroundService.java

/**
 * Register an SMS Data (Binary) Receiver
 *//*  www.j a va  2  s  .  co  m*/
private void registerSmsReceiver() {
    smsReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Debug.i("Received Binary SMS");

            Bundle bundle = intent.getExtras();
            SmsMessage[] msgs = null;

            if (null != bundle) {
                // In telecommunications the term (PDU) means protocol data
                // unit.
                // There are two ways of sending and receiving SMS messages:
                // by text mode and by PDU (protocol description unit) mode.
                // The PDU string contains not only the message, but also a
                // lot of meta-information about the sender, his SMS service
                // center, the time stamp etc
                // It is all in the form of hexa-decimal octets or decimal
                // semi-octets.
                Object[] pdus = (Object[]) bundle.get("pdus");
                msgs = new SmsMessage[pdus.length];

                for (int i = 0; i < msgs.length; i++) {
                    // Create the Message
                    msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                    // Get Message Parameters
                    SmsObject receivedSms = new SmsObject();
                    receivedSms.setTelephoneNumber(msgs[i].getOriginatingAddress());
                    receivedSms.setMessageTimestamp(msgs[i].getTimestampMillis());
                    receivedSms.setMessageData(Base64.encodeToString(msgs[i].getUserData(), Base64.CRLF));

                    Debug.d("Received SMS and it's content hash is: " + BinaryHelpers
                            .toHexadecimealString(Hashing.getMD5Hash(msgs[i].getUserData()).toByteArray()));

                    // Store the SmsObject to the db
                    dao.storeSms(receivedSms);
                }
            }

            // This will stop the Broadcast and not allow the message to
            // be interpreted by the default Android app or other apps
            abortBroadcast();
        }
    };

    // Set up the Receiver Parameters
    IntentFilter mIntentFilter = new IntentFilter();
    mIntentFilter.setPriority(999);
    mIntentFilter.addAction("android.intent.action.DATA_SMS_RECEIVED");
    mIntentFilter.addDataScheme("sms");
    // Set the Port that is listening to
    mIntentFilter.addDataAuthority("*", "2013");
    // mIntentFilter.addDataType(type)
    registerReceiver(smsReceiver, mIntentFilter);
    Debug.d("Set up BinarySMS receiver.");
}

From source file:com.example.ramesh.p2pfileshare.ClientActivity.java

public void sendFile() {

    //Only try to send file if there isn't already a transfer active
    if (!transferActive) {
        if (!filePathProvided) {
            setClientFileTransferStatus("Select a file to send before pressing send");
        } else if (!connectedAndReadyToSendFile) {
            setClientFileTransferStatus("You must be connected to a server before attempting to send a file");
        }// www.  j ava  2 s  . co m
        /*
        else if(targetDevice == null)
        {
           setClientFileTransferStatus("Target Device network information unknown");
        }
        */
        else if (wifiInfo == null) {
            setClientFileTransferStatus("Missing Wifi P2P information");
        } else {
            //Launch client service
            clientServiceIntent = new Intent(this, ClientService.class);
            clientServiceIntent.putExtra("fileToSend", fileToSend);
            clientServiceIntent.putExtra("port", new Integer(port));
            //clientServiceIntent.putExtra("targetDevice", targetDevice);
            clientServiceIntent.putExtra("wifiInfo", wifiInfo);
            clientServiceIntent.putExtra("clientResult", new ResultReceiver(null) {
                @Override
                protected void onReceiveResult(int resultCode, final Bundle resultData) {

                    if (resultCode == port) {
                        if (resultData == null) {
                            //Client service has shut down, the transfer may or may not have been successful. Refer to message 
                            transferActive = false;
                        } else {
                            final TextView client_status_text = (TextView) findViewById(
                                    R.id.file_transfer_status);

                            client_status_text.post(new Runnable() {
                                public void run() {
                                    client_status_text.setText((String) resultData.get("message"));
                                }
                            });
                        }
                    }

                }
            });

            transferActive = true;
            startService(clientServiceIntent);

            //end
        }
    }
}

From source file:com.facebook.GraphRequest.java

private static void serializeParameters(Bundle bundle, Serializer serializer, GraphRequest request)
        throws IOException {
    Set<String> keys = bundle.keySet();

    for (String key : keys) {
        Object value = bundle.get(key);
        if (isSupportedParameterType(value)) {
            serializer.writeObject(key, value, request);
        }/*from   w  ww.  ja va  2  s  . c o  m*/
    }
}

From source file:org.camlistore.UploadService.java

private void handleSend(Intent intent) {
    Bundle extras = intent.getExtras();
    if (extras == null) {
        Log.w(TAG, "expected extras in handleSend");
        return;/*from  w  w  w .  j  a  v a  2 s.c  o  m*/
    }

    extras.keySet(); // unparcel
    Log.d(TAG, "handleSend; extras=" + extras);

    Object streamValue = extras.get("android.intent.extra.STREAM");
    if (!(streamValue instanceof Uri)) {
        Log.w(TAG, "Expected URI for STREAM; got: " + streamValue);
        return;
    }

    final Uri uri = (Uri) streamValue;
    Util.runAsync(new Runnable() {
        @Override
        public void run() {
            try {
                service.enqueueUpload(uri);
            } catch (RemoteException e) {
            }
        }
    });
}

From source file:com.neighbor.ex.tong.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            Log.e("GcmIntentService", "Send error : " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.e("GcmIntentService", "Deleted messages on server : " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            String msg = "";
            String SenderCarNo = "";
            String Userseq = "";

            Iterator<String> iterator = extras.keySet().iterator();
            while (iterator.hasNext()) {
                String key = iterator.next();
                String value = extras.get(key).toString();
                try {
                    if (key.equals("MESSAGE"))
                        msg = URLDecoder.decode(value, "utf-8");
                    if (key.equals("SENDER_CAR_NUM"))
                        SenderCarNo = URLDecoder.decode(value, "utf-8");
                    if (key.equals("SENDER_SEQ")) {
                        Userseq = String.valueOf(value);
                    }/*from w  ww  .  j  ava 2  s  .  c om*/
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            if (!msg.equalsIgnoreCase("UPDATE_OK") && !msg.equalsIgnoreCase("")) {

                ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
                List<ActivityManager.RunningTaskInfo> services = am.getRunningTasks(Integer.MAX_VALUE);

                boolean isRunning = false;

                if (services.get(0).topActivity.getPackageName().toString()
                        .equalsIgnoreCase(this.getPackageName().toString())) {
                    isRunning = true;
                }

                if (false == isRunning) {
                    Uri path = getSoundPath(msg);
                    NotiMessage(msg, path);
                } else {
                    mHandler.post(new DisplayToast(this, msg));
                }

                //                    Log.d("hts", "sendGCMIntent msg : " + msg + "\t Userseq : " + Userseq + "\t SenderCarNo : " + SenderCarNo);
                sendGCMIntent(GcmIntentService.this, msg, null, SenderCarNo, Userseq);
            }
        }
    }

    GCMBroadCastReceiver.completeWakefulIntent(intent);
}

From source file:com.juick.android.TagsFragment.java

@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    myView = view;//from   www. j  av  a2 s  . c o m
    Bundle args = getArguments();
    myAll = view.findViewById(R.id.myAll);
    if (PointMessageID.CODE.equals(args.getString("microblog"))) {
        myAll.setVisibility(View.GONE); // not visible for point
    }
    myAll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showMine = !showMine;
            if (saveMineAll) {
                sp.edit().putBoolean("showMine", showMine).commit();
            }
            reloadTags(view);
        }
    });
    if (args != null) {
        uid = args.getInt("uid", 0);
        uidS = args.getString("user");
        multi = args.getBoolean("multi", false);
        if (uid == 0) {
            MessagesSource messagesSource = (MessagesSource) args.get("messagesSource");
            if (messagesSource instanceof JuickCompatibleURLMessagesSource) {
                JuickCompatibleURLMessagesSource jcums = (JuickCompatibleURLMessagesSource) messagesSource;
                String user_idS = jcums.getArg("user_id");
                if (user_idS != null) {
                    try {
                        uid = Integer.parseInt(user_idS);
                    } catch (Throwable x) {
                    }
                }
            }
        }
    }

    //        getListView().setOnItemClickListener(this);
    //        getListView().setOnItemLongClickListener(this);

    //        MessagesFragment.installDividerColor(getListView());
    MainActivity.restyleChildrenOrWidget(view);
    final TextView progress = (TextView) myView.findViewById(R.id.progress);
    final View okbutton = myView.findViewById(R.id.okbutton);
    progress.setText(R.string.Loading___);
    okbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final TextView selected = (TextView) myView.findViewById(R.id.selected);
            String selectedText = selected.getText().toString();
            String[] split = selectedText.split(" ");
            for (String s : split) {
                if (s.length() == 0)
                    continue;
                if (!s.startsWith("*") || s.length() < 2) {
                    Toast.makeText(getActivity(), getActivity().getString(R.string.TagsFormatError),
                            Toast.LENGTH_LONG).show();
                    return;
                }
            }
            parentActivity.onTagClick(selectedText, uid);
        }
    });

    reloadTags(view);
}