Example usage for android.content Intent getExtras

List of usage examples for android.content Intent getExtras

Introduction

In this page you can find the example usage for android.content Intent getExtras.

Prototype

public @Nullable Bundle getExtras() 

Source Link

Document

Retrieves a map of extended data from the intent.

Usage

From source file:edu.mines.letschat.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*/*  w  w  w  .  ja  v  a 2 s  .c  om*/
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification("Send error: " + extras.toString(), "0");
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " + extras.toString(), "0");
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.
            //                for (int i = 0; i < 5; i++) {
            //                    Log.i(TAG, "Working... " + (i + 1)
            //                            + "/5 @ " + SystemClock.elapsedRealtime());
            //                    try {
            //                        Thread.sleep(5000);
            //                    } catch (InterruptedException e) {
            //                    }
            //                }
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.

            String message = (String) extras.get("message");
            messages.add(message);

            String picture = (String) extras.get("picture");

            String senderID = (String) extras.get("sender");
            String recipientID = (String) extras.get("recipient");
            sendNotification(message, senderID);
            Log.v(TAG, "Received: " + message);

            Log.i(TAG, "Received: " + extras.toString());
            Intent resultBroadCastIntent = new Intent();
            /*set action here*/
            resultBroadCastIntent.setAction(
                    edu.mines.letschat.MessageActivity.TextCapitalizeResultReceiver.ACTION_TEXT_CAPITALIZED);
            /*set intent category as default*/
            resultBroadCastIntent.addCategory(Intent.CATEGORY_DEFAULT);

            /*add data to intent*/
            resultBroadCastIntent.putExtra(OUTPUT_TEXT, message);
            //              Log.v(TAG, "Sender id " + senderID + " recieve id " + recipientID);
            Log.v(TAG, picture);
            Conversation convo = new Conversation(getApplicationContext(), senderID, recipientID, message,
                    false, picture);
            convo.save();

            if (!picture.isEmpty()) {
                new DownloadImage(picture).execute();
            }

            /*send broadcast */
            sendBroadcast(resultBroadCastIntent);
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReviever.completeWakefulIntent(intent);
}

From source file:com.android.gallery3d.app.Gallery.java

private void startGetContent(Intent intent) {
    Bundle data = intent.getExtras() != null ? new Bundle(intent.getExtras()) : new Bundle();
    data.putBoolean(KEY_GET_CONTENT, true);
    int typeBits = GalleryUtils.determineTypeBits(this, intent);
    data.putInt(KEY_TYPE_BITS, typeBits);
    data.putString(AlbumSetPage.KEY_MEDIA_PATH, getDataManager().getTopSetPath(typeBits));
    getStateManager().setLaunchGalleryOnTop(true);
    getStateManager().startState(AlbumSetPage.class, data);
}

From source file:cc.softwarefactory.lokki.android.activities.SignUpActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (data == null) {
        Log.e(TAG, "Get default account returned null. Nothing to do.");
        return;//from www  .  j  a v  a  2s .  c  o  m
    }
    Log.e(TAG, "onActivityResult. Data: " + data.getExtras());
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_EMAIL && resultCode == RESULT_OK) {
        String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
        if (accountName != null) {
            aq.id(R.id.email).text(accountName);
        }
    }
}

From source file:it.mb.whatshare.SendToGCMActivity.java

private void shareViaGCM(Intent intent) {
    String subject = intent.getExtras().getString(Intent.EXTRA_SUBJECT);
    String text = intent.getExtras().getString(Intent.EXTRA_TEXT);
    String type = intent.getExtras().getString(MainActivity.INTENT_TYPE_EXTRA);
    if (type == null)
        type = MainActivity.SHARE_VIA_WHATSAPP_EXTRA;
    if (mustIncludeSubject(subject, text)) {
        text = subject + " - " + text;
    }//ww w. j a  va2 s  . c  om
    int sharedWhat = text.contains("http://") ? R.string.link : R.string.selection;
    Utils.debug("sharing with %s this: '%s'", outboundDevice.type, text);
    new CallGCM().execute(text, type);
    tracker.sendEvent("gcm", "share", sharedWhat == R.string.link ? "link" : "text", 0L);
    showNotification(sharedWhat, MainActivity.SHARE_VIA_WHATSAPP_EXTRA.equals(type));
}

From source file:com.pinplanet.pintact.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    System.out.println("==== Push Notification: GcmIntentService::onHandleIntent");

    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*//w w  w  .  ja  va2 s.  c  o m
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification("Send error: " + extras.toString(), extras.getString("customData"));
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " + extras.toString(),
                    extras.getString("customData"));
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.
            /*
            for (int i = 0; i < 5; i++) {
            Log.i(TAG, "Working... " + (i + 1)
                    + "/5 @ " + SystemClock.elapsedRealtime());
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            }
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            */
            // Post notification of received message.
            Log.d(TAG, "Notification Received");
            Log.d(TAG, "text: " + extras.getString("text"));
            Log.d(TAG, "customData: " + extras.getString("customData"));
            sendNotification(extras.getString("text"), extras.getString("customData"));
            //Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:uk.ac.horizon.ubihelper.service.PeerManager.java

/** public API - matches */
public static synchronized boolean matches(PeerRequestInfo pi, Intent i) {
    String sourceip = i.getExtras().getString(EXTRA_SOURCEIP);
    String name = i.getExtras().getString(EXTRA_NAME);
    if (pi.instanceName.equals(name) && pi.src.getHostAddress().equals(sourceip))
        return true;
    return false;
}

From source file:com.appdynamics.demo.gasp.service.RESTIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Uri action = intent.getData();/*from  w  w  w  . j ava 2 s . co  m*/
    Bundle extras = intent.getExtras();

    if (extras == null || action == null || !extras.containsKey(EXTRA_RESULT_RECEIVER)) {
        Log.e(TAG, "You did not pass extras or data with the Intent.");
        return;
    }

    int verb = extras.getInt(EXTRA_HTTP_VERB, GET);
    Bundle params = extras.getParcelable(EXTRA_PARAMS);
    Bundle headers = extras.getParcelable(EXTRA_HEADERS);
    ResultReceiver receiver = extras.getParcelable(EXTRA_RESULT_RECEIVER);

    try {
        HttpRequestBase request = null;

        // Get query params from Bundle and build URL
        switch (verb) {
        case GET: {
            request = new HttpGet();
            attachUriWithQuery(request, action, params);
        }
            break;

        case DELETE: {
            request = new HttpDelete();
            attachUriWithQuery(request, action, params);
        }
            break;

        case POST: {
            request = new HttpPost();
            request.setURI(new URI(action.toString()));

            HttpPost postRequest = (HttpPost) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                postRequest.setEntity(formEntity);
            }
        }
            break;

        case PUT: {
            request = new HttpPut();
            request.setURI(new URI(action.toString()));

            HttpPut putRequest = (HttpPut) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                putRequest.setEntity(formEntity);
            }
        }
            break;
        }

        // Get Headers from Bundle
        for (BasicNameValuePair header : paramsToList(headers)) {
            request.setHeader(header.getName(), header.getValue());
        }

        if (request != null) {
            HttpClient client = new DefaultHttpClient();

            Log.d(TAG, "Executing request: " + verbToString(verb) + ": " + action.toString());

            HttpResponse response = client.execute(request);

            HttpEntity responseEntity = response.getEntity();
            StatusLine responseStatus = response.getStatusLine();
            int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0;

            if ((responseEntity != null) && (responseStatus.getStatusCode() == 200)) {
                Bundle resultData = new Bundle();
                resultData.putString(REST_RESULT, EntityUtils.toString(responseEntity));
                receiver.send(statusCode, resultData);
            } else {
                receiver.send(statusCode, null);
            }
        }
    } catch (URISyntaxException e) {
        Log.e(TAG, "URI syntax was incorrect. " + verbToString(verb) + ": " + action.toString(), e);
        receiver.send(0, null);
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "A UrlEncodedFormEntity was created with an unsupported encoding.", e);
        receiver.send(0, null);
    } catch (ClientProtocolException e) {
        Log.e(TAG, "There was a problem when sending the request.", e);
        receiver.send(0, null);
    } catch (IOException e) {
        Log.e(TAG, "There was a problem when sending the request.", e);
        receiver.send(0, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.chess.genesis.net.GenesisNotifier.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startid) {
    final Bundle bundle = intent.getExtras();
    fromalarm = bundle != null && bundle.getBoolean("fromAlarm", false);

    new Thread(this).start();
    return START_NOT_STICKY;
}

From source file:net.networksaremadeofstring.rhybudd.ZenossEvent.java

public ZenossEvent(Intent intent) {
    this.Count = Integer.getInteger(intent.getExtras().getString("count"));
    this.evid = intent.getExtras().getString("evid");
    this.device = intent.getExtras().getString("device");
    this.summary = intent.getExtras().getString("summary");
    this.severity = intent.getExtras().getString("severity");
    this.eventClass = intent.getExtras().getString("event_class");
    //String event_class_key = intent.getExtras().getString("event_class_key");
    //String sent = intent.getExtras().getString("sent");
}

From source file:net.carlh.toast.MainActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == TimerFragment.ADD_OR_UPDATE_RULE && data != null) {
        state.addOrReplace((Rule) data.getExtras().getSerializable("rule"));
    }//from ww  w  . j  a  v  a  2 s. c  o m
}