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:com.example.pushtester.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.i(TAG, "GcmIntentService started");
    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
        /*/*from w  w w.jav  a 2s .  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());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " + extras.toString());
            // 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.
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.
            if (extras.getString("msg") != null) {
                Log.i(TAG, "msg found");
                sendNotification(extras.getString("msg"));
            } else if (extras.getString("buddyscores") != null) {
                Log.i(TAG, "buddyscores found");
                try {
                    JSONArray jsonArray = new JSONArray(extras.getString("buddyscores"));
                    Log.i(GcmIntentService.class.getName(), "Number of entries " + jsonArray.length());
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                        Log.i(GcmIntentService.class.getName(), jsonObject.getString("text"));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                Log.i(TAG, "else");
                sendNotification("Received: " + extras.toString());
            }
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.NotifyMe.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
        /*//from  w w  w  .  java2 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());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            String service = extras.getString("service");
            if (service.equals("NotifyMe")) {
                sendNotification(extras.getString("message"));
            } else {
                sendNotificationWithExtras(extras);
            }

            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.rampgreen.caretakermobile.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

        /*/*from  w  w w  .j  a v a2s  .  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("Error", "Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted Messages", "Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            GcmMsgBean gcmMsgBean = null;
            String msg = null;
            try {
                msg = extras.getString("message");
                JSONObject jsonObject = new JSONObject(msg);
                gcmMsgBean = new GcmMsgBean();
                gcmMsgBean.parseGcmMsg(jsonObject);
            } catch (JSONException e) {
                AppLog.printStackTrace(e);
            }

            if (gcmMsgBean == null || msg == null) {
                return;
            }

            String title = gcmMsgBean.getNotificationTitle();
            String subtitle = gcmMsgBean.getNotificationSubTitle();
            msg = title + ":" + subtitle;
            String msgList = (String) AppSettings.getPrefernce(this, null, AppSettings.STORE_NOTI_LIST, "");
            if (StringUtils.isEmpty(msgList)) {
                msgList = msg;
            } else {
                msgList = msgList + "|" + msg;
            }
            AppSettings.setPreference(this, null, AppSettings.STORE_NOTI_LIST, msgList);
            sendNotification(gcmMsgBean.getNotificationTitle(), gcmMsgBean.getNotificationSubTitle());
            AppLog.d(TAG, "Received: " + extras.toString());

        }

        // 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.

        //         }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.rocketsingh.biker.GCMIntentService.java

@Override
protected void onMessage(Context context, Intent intent) {
    AppLog.Log(TAG, "Received bundle : " + intent.getExtras());
    // String message = getString(R.string.gcm_message);
    String message = intent.getExtras().getString("message");
    AppLog.Log(TAG, "Message is: --->" + message);
    Log.d("mahi", "push notification " + intent.getExtras());
    String team = intent.getExtras().getString("team");
    if (message != null && team != null) {
        Intent pushIntent = new Intent(AndyConstants.NEW_REQUEST);
        pushIntent.putExtra(AndyConstants.NEW_REQUEST, team);
        // String messageBedge = intent.getExtras().getString("bedge");
        CommonUtilities.displayMessage(context, message);
        // notifies user
        try {// w w  w .  j  a  va2s.  c  o  m
            JSONObject jsonObject = new JSONObject(team);
            if (jsonObject.getInt(AndyConstants.Params.UNIQUE_ID) == 1) {
                generateNotification(context, message);
            } else {
                preferenceHelper = new PreferenceHelper(context);
                preferenceHelper.clearRequestData();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        LocalBroadcastManager.getInstance(context).sendBroadcast(pushIntent);
    }
}

From source file:de.golov.zeitgeistreich.ZeitGeistReichActivity.java

/** Called when the activity is first created. */
@Override//from www .java  2s  . c om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final ImageView imagePreview = (ImageView) findViewById(R.id.ImagePreview);
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    Uri mImageUri = null;
    if (Intent.ACTION_SEND.equals(intent.getAction()) && extras != null) {
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            mImageUri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            if (mImageUri != null) {
                int origId = Integer.parseInt(mImageUri.getLastPathSegment());
                Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), origId,
                        MediaStore.Images.Thumbnails.MINI_KIND, (BitmapFactory.Options) null);
                imagePreview.setImageBitmap(bitmap);
            }
        }
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,
            tag_suggests);
    final MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(R.id.TagEditView);
    textView.setAdapter(adapter);
    textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    final Button button = (Button) findViewById(R.id.ZeitgeistSubmit);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            submitImage(textView.getText().toString());
        }
    });
}

From source file:org.deviceconnect.message.intent.event.IntentEventManager.java

/**
 * ????.//w ww.  j  ava 2s.  com
 * 
 * @param event 
 */
public void sendEvent(final Intent event) {

    try {
        JSONObject json = JSONFactory.convertBundleToJSON(event.getExtras());
        sendEvent(json);
    } catch (JSONException e) {
        mLogger.warning("IntentEventManager#sendEvent. Exception : " + e.getMessage());
    }

}

From source file:com.yozio.demo.implementations.facebook.PostPhotoActivity.java

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

    if (intent != null) {
        Bundle extras = intent.getExtras();
        mImageBitmap = (Bitmap) extras.get("data");

        if (mImageBitmap != null) {
            mImageView.setImageBitmap(mImageBitmap);
            btnPostPhoto.setVisibility(View.VISIBLE);
        } else {/*w  w w.j a  v  a2s.c o  m*/
            btnPostPhoto.setVisibility(View.GONE);
        }
    }

}

From source file:jahirfiquitiva.iconshowcase.services.MuzeiArtSourceService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    String command = intent.getExtras().getString("service");
    if (command != null) {
        try {// ww  w .j  a  v a  2 s .c o  m
            onTryUpdate(UPDATE_REASON_USER_NEXT);
        } catch (RetryException e) {
            Utils.showLog("Error updating Muzei: " + e.getLocalizedMessage());
        }
    }
    return super.onStartCommand(intent, flags, startId);
}

From source file:de.grobox.blitzmail.NotificationHandlerActivity.java

@Override
protected void onNewIntent(Intent intent) {
    Bundle extras = intent.getExtras();

    // show dialog for server errors
    if (extras != null && extras.getString("ContentTitle").equals(getString(R.string.error))) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setTitle(getString(R.string.app_name) + " - " + getString(R.string.error));
        builder.setMessage(extras.getString("ContentText"));
        builder.setIcon(android.R.drawable.ic_dialog_alert);

        // Add the buttons
        builder.setNegativeButton(getResources().getString(R.string.dismiss),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        deleteMail();//from ww  w  .  j a v a 2  s  . co m
                        // User clicked Cancel button, close this Activity
                        finish();
                    }
                });
        builder.setNeutralButton(getResources().getString(R.string.send_later),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // User clicked Cancel button
                        if (BuildConfig.PRO) {
                            // close this Activity
                            finish();
                        } else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(context);

                            builder.setTitle(getString(R.string.app_name));
                            builder.setMessage(getString(R.string.error_lite_version));
                            builder.setIcon(android.R.drawable.ic_dialog_info);

                            // Add the buttons
                            builder.setPositiveButton(android.R.string.ok,
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface lite_dialog, int id) {
                                            Uri uri = Uri.parse(
                                                    "https://play.google.com/store/apps/details?id=de.grobox.blitzmail.pro");
                                            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                                            if (intent.resolveActivity(getPackageManager()) != null) {
                                                startActivity(intent);
                                            }
                                            lite_dialog.dismiss();
                                            finish();
                                        }
                                    });
                            builder.setNegativeButton(android.R.string.cancel,
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface lite_dialog, int id) {
                                            lite_dialog.dismiss();
                                            finish();
                                        }
                                    });

                            // Create and show the AlertDialog
                            AlertDialog lite_dialog = builder.create();
                            lite_dialog.setCanceledOnTouchOutside(false);
                            lite_dialog.show();
                        }
                    }
                });
        builder.setPositiveButton(getResources().getString(R.string.try_again),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // Prepare start of new activity
                        Intent intent = new Intent(context, SendActivity.class);
                        intent.setAction("BlitzMailReSend");
                        intent.putExtra("mail", mMail.toString());
                        finish();

                        startActivity(intent);
                    }
                });

        // Create and show the AlertDialog
        AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
    } else {
        // close activity
        finish();
    }
}

From source file:ch.fixme.status.Widget_config.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.widget_config);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(Widget_config.this);
    getDirTask = new GetDirTask();
    getDirTask.execute(ParseGeneric.API_DIRECTORY);
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    findViewById(R.id.choose_ok).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Editor edit = mPrefs.edit();
            edit.putBoolean(Prefs.KEY_WIDGET_TRANSPARENCY,
                    ((CheckBox) findViewById(R.id.choose_transparency)).isChecked());
            edit.commit();/* w  ww .j av a  2s. c om*/
            setWidgetAlarm();
            finish();
        }
    });
    ((CheckBox) findViewById(R.id.choose_transparency))
            .setChecked(mPrefs.getBoolean(Prefs.KEY_WIDGET_TRANSPARENCY, Prefs.DEFAULT_WIDGET_TRANSPARENCY));
    ((CheckBox) findViewById(R.id.choose_text))
            .setChecked(mPrefs.getBoolean(Prefs.KEY_WIDGET_TEXT, Prefs.DEFAULT_WIDGET_TEXT));
    ((EditText) findViewById(R.id.choose_update)).addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String inter = s.toString();
            if (!"".equals(inter) && !"0".equals(inter)) {
                Editor edit = mPrefs.edit();
                edit.putString(Prefs.KEY_CHECK_INTERVAL, inter);
                edit.commit();
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
}