Example usage for android.content Intent putExtras

List of usage examples for android.content Intent putExtras

Introduction

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

Prototype

public @NonNull Intent putExtras(@NonNull Bundle extras) 

Source Link

Document

Add a set of extended data to the intent.

Usage

From source file:com.eusecom.saminveantory.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.mojeobj) {

        Intent is = new Intent(getApplicationContext(), VladciSDActivity.class);
        startActivity(is);/*from w  w w. j  av a  2 s .  com*/
        return true;
    }

    if (id == R.id.preferences) {

        Intent is = new Intent(getApplicationContext(), MyPreferencesActivity.class);
        startActivity(is);
        return true;
    }

    if (id == R.id.setnostroreinventory) {

        Intent idm = new Intent(getApplicationContext(), InvsetActivity.class);
        Bundle extrasdm = new Bundle();
        extrasdm.putString("page", "3");
        idm.putExtras(extrasdm);
        startActivity(idm);
        return true;
    }

    if (id == R.id.delinventory) {

        Intent idm = new Intent(getApplicationContext(), InvsetActivity.class);
        Bundle extrasdm = new Bundle();
        extrasdm.putString("page", "0");
        idm.putExtras(extrasdm);
        startActivity(idm);
        return true;
    }

    if (id == R.id.delinventory_nostore) {

        Intent idm = new Intent(getApplicationContext(), InvsetActivity.class);
        Bundle extrasdm = new Bundle();
        extrasdm.putString("page", "2");
        idm.putExtras(extrasdm);
        startActivity(idm);
        return true;
    }

    if (id == R.id.demoresources) {

        Intent idm = new Intent(getApplicationContext(), InvsetActivity.class);
        Bundle extrasdm = new Bundle();
        extrasdm.putString("page", "1");
        idm.putExtras(extrasdm);
        startActivity(idm);
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:ca.ualberta.cs.bkhunter_notes.AddClaimActivity.java

public void addExpenseAction(View v) {

    //each of these correspond to the text input in each field
    EditText nameTextView = (EditText) findViewById(R.id.claimText);
    EditText descriptionTextView = (EditText) findViewById(R.id.descrText);
    EditText dateFromTextView = (EditText) findViewById(R.id.dateFromText);
    EditText dateToTextView = (EditText) findViewById(R.id.dateToText);

    String name = nameTextView.getText().toString();
    String description = descriptionTextView.getText().toString();
    String date_from = dateFromTextView.getText().toString();
    String date_to = dateToTextView.getText().toString();

    // The date input is a String, and must be convert to type Date to sort
    // This method inspired by User Korcholis @
    // http://stackoverflow.com/questions/12455905/how-to-convert-string-to-date-in-android on 02/01/2015
    SimpleDateFormat makeFormat = new SimpleDateFormat("yyyy-MM-dd");

    Date date2 = null;//from   w  ww  . j  av  a2s  . c  o  m
    Date date3 = null;
    ;

    try {
        date3 = (Date) makeFormat.parse(date_to);
        date2 = (Date) makeFormat.parse(date_from);

        Intent intent = new Intent(AddClaimActivity.this, AddExpenseActivity.class);

        Bundle bundle = new Bundle();
        bundle.putString("name", name);
        bundle.putString("desc", description);
        bundle.putString("DF", date_from);
        bundle.putString("DT", date_to);

        intent.putExtras(bundle);

        startActivity(intent);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        //e.printStackTrace();
        Toast.makeText(this, "Pleae enter date in specified format", Toast.LENGTH_LONG).show();

    }

}

From source file:com.irccloud.android.activity.QuickReplyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quick_reply);

    if (getIntent().hasExtra("cid") && getIntent().hasExtra("bid")) {
        onNewIntent(getIntent());//www  .j  a  va 2  s .  c  o m
    } else {
        finish();
        return;
    }

    final ImageButton send = (ImageButton) findViewById(R.id.sendBtn);
    final EditText message = (EditText) findViewById(R.id.messageTxt);
    message.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            if (actionId == EditorInfo.IME_ACTION_SEND && message.getText() != null
                    && message.getText().length() > 0)
                send.performClick();
            return true;
        }
    });
    message.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER
                    && message.getText() != null && message.getText().length() > 0)
                send.performClick();
            return false;
        }
    });
    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (message.getText() != null && message.getText().length() > 0) {
                Intent i = new Intent(RemoteInputService.ACTION_REPLY);
                i.setComponent(new ComponentName(getPackageName(), RemoteInputService.class.getName()));
                i.putExtras(getIntent());
                i.putExtra("reply", message.getText().toString());
                startService(i);
                finish();
            }
        }
    });

    ListView listView = (ListView) findViewById(R.id.conversation);
    listView.setAdapter(adapter);
}

From source file:com.apps.mohb.wifiauthority.AboutActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    DialogFragment dialog;//from  w w  w. ja  v a  2  s .co  m
    Intent intent;
    Bundle bundle;

    switch (id) {

    // Feedback
    case R.id.action_feedback:
        intent = new Intent(this, FeedbackActivity.class);
        bundle = new Bundle();
        bundle.putString("url", getString(R.string.url_contact));
        intent.putExtras(bundle);
        startActivity(intent);
        break;

    // Bug report
    case R.id.action_bug_report:
        intent = new Intent(this, FeedbackActivity.class);
        bundle = new Bundle();
        bundle.putString("url", getString(R.string.url_bug_report));
        intent.putExtras(bundle);
        startActivity(intent);
        break;

    // Terms of use
    case R.id.action_terms_of_use:
        dialog = new TermsOfUseDialogFragment();
        dialog.show(getSupportFragmentManager(), "TermsOfUseDialogFragment");
        break;

    // Privacy policy
    case R.id.action_privacy_policy:
        dialog = new PrivacyPolicyDialogFragment();
        dialog.show(getSupportFragmentManager(), "PrivacyPolicyDialogFragment");
        break;

    // Legal notices
    case R.id.action_legal_notices:
        new GetLegalNotices().execute();
        break;

    // Icons attribution
    case R.id.action_material_icons:
        dialog = new MaterialIconsDialogFragment();
        dialog.show(getSupportFragmentManager(), "MaterialIconsDialogFragment");
        break;

    }

    return super.onOptionsItemSelected(item);
}

From source file:com.android.tv.TvApplication.java

private void startMainActivity(Bundle extras) {
    // The use of FLAG_ACTIVITY_NEW_TASK enables arbitrary applications to access the intent
    // sent to the root activity. Having said that, we should be fine here since such an intent
    // does not carry any important user data.
    Intent intent = new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (extras != null) {
        intent.putExtras(extras);
    }//ww  w  .ja  v a2s .c  o  m
    startActivity(intent);
}

From source file:most.voip.example.remote_config.LoginActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == REMOTE_ACCOUNT_CONFIG_REQUEST) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
            Intent resultIntent = new Intent();
            Bundle b = new Bundle();
            b.putString("account_data", data.getExtras().getString("account_data"));
            b.putString("buddies_data", data.getExtras().getString("buddies_data"));

            resultIntent.putExtras(b);
            // TODO Add extras or a data URI to this intent as appropriate.
            Log.d("VoipConfigDemo", "Configuration accepted");
            setResult(Activity.RESULT_OK, resultIntent);

            finish();/*from w ww .  j  a v  a  2s . c  o m*/
        } else {
            Log.d("VoipConfigDemo", "Account data NOT received from the activity");
        }
    } else {
        Log.d("VoipConfigDemo", "Received unknown requestCode:" + String.valueOf(requestCode));
    }
}

From source file:br.com.imovelhunter.imovelhunterwebmobile.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent in = new Intent(this, ChatActivity.class);

    Bundle extras = new Bundle();
    extras.putSerializable(Parametros.MENSAGEM_JSON.name(), this.mensagem);
    extras.putSerializable(ParametrosSessao.USUARIO_CHAT_ATUAL.name(), this.mensagem.getUsuarioRemetente());

    in.putExtras(extras);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, in, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icone)
            .setContentTitle("Imovel Hunter - " + mensagem.getUsuarioRemetente().getNomeUsuario())
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

    mBuilder.setAutoCancel(true);/*from   www  . j  a va  2 s .c  o  m*/

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

    this.vibrar();
}

From source file:com.parse.ParsePushBroadcastReceiver.java

/**
 * Creates a {@link Notification} with reasonable defaults. If "alert" and "title" are
 * both missing from data, then returns {@code null}. If the text in the notification is longer
 * than 38 characters long, the style of the notification will be set to
 * {@link android.app.Notification.BigTextStyle}.
 * <p/>/*w  w  w.j  a v  a  2  s .  c  o  m*/
 * As a security precaution, developers overriding this method should be sure to set the package
 * on notification {@code Intent}s to avoid leaking information to other apps.
 *
 * @param context
 *      The {@code Context} in which the receiver is running.
 * @param intent
 *      An {@code Intent} containing the channel and data of the current push notification.
 * @return
 *      The notification to be displayed.
 *
 * @see ParsePushBroadcastReceiver#onPushReceive(Context, Intent)
 */
protected Notification getNotification(Context context, Intent intent) {
    JSONObject pushData = getPushData(intent);
    if (pushData == null || (!pushData.has("alert") && !pushData.has("title"))) {
        return null;
    }

    String title = pushData.optString("title", ManifestInfo.getDisplayName(context));
    String alert = pushData.optString("alert", "Notification received.");
    String tickerText = String.format(Locale.getDefault(), "%s: %s", title, alert);

    Bundle extras = intent.getExtras();

    Random random = new Random();
    int contentIntentRequestCode = random.nextInt();
    int deleteIntentRequestCode = random.nextInt();

    // Security consideration: To protect the app from tampering, we require that intent filters
    // not be exported. To protect the app from information leaks, we restrict the packages which
    // may intercept the push intents.
    String packageName = context.getPackageName();

    Intent contentIntent = new Intent(ParsePushBroadcastReceiver.ACTION_PUSH_OPEN);
    contentIntent.putExtras(extras);
    contentIntent.setPackage(packageName);

    Intent deleteIntent = new Intent(ParsePushBroadcastReceiver.ACTION_PUSH_DELETE);
    deleteIntent.putExtras(extras);
    deleteIntent.setPackage(packageName);

    PendingIntent pContentIntent = PendingIntent.getBroadcast(context, contentIntentRequestCode, contentIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent pDeleteIntent = PendingIntent.getBroadcast(context, deleteIntentRequestCode, deleteIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // The purpose of setDefaults(Notification.DEFAULT_ALL) is to inherit notification properties
    // from system defaults
    NotificationCompat.Builder parseBuilder = new NotificationCompat.Builder(context);
    parseBuilder.setContentTitle(title).setContentText(alert).setTicker(tickerText)
            .setSmallIcon(this.getSmallIconId(context, intent)).setLargeIcon(this.getLargeIcon(context, intent))
            .setContentIntent(pContentIntent).setDeleteIntent(pDeleteIntent).setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL);
    if (alert != null && alert.length() > ParsePushBroadcastReceiver.SMALL_NOTIFICATION_MAX_CHARACTER_LIMIT) {
        parseBuilder.setStyle(new NotificationCompat.Builder.BigTextStyle().bigText(alert));
    }
    return parseBuilder.build();
}

From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java

private void startProfileOwnerProvisioning() {
    Intent intent = new Intent(this, ProfileOwnerProvisioningActivity.class);
    intent.putExtras(getIntent());
    startActivityForResult(intent, PROVISIONING_REQUEST_CODE);
}

From source file:com.aniruddhc.acemusic.player.Dialogs.AddMusicLibraryDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    libraryLabelID = "circle_blue_dark";
    View rootView = getActivity().getLayoutInflater().inflate(R.layout.dialog_add_music_library, null);
    TextView instructions = (TextView) rootView.findViewById(R.id.add_music_library_instructions);
    instructions.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light"));
    instructions.setPaintFlags(instructions.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    final ImageButton labelButton = (ImageButton) rootView.findViewById(R.id.add_music_library_label_button);
    final EditText musicLibraryName = (EditText) rootView.findViewById(R.id.add_music_library_text_field);
    musicLibraryName.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light"));
    musicLibraryName//from w w w. j  a  v  a  2 s.co m
            .setPaintFlags(musicLibraryName.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    labelButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            //Create a new array with a list of all the library labels.
            final Drawable[] labelsArray = {
                    getActivity().getResources().getDrawable(R.drawable.circle_blue_dark),
                    getActivity().getResources().getDrawable(R.drawable.circle_blue_light),
                    getActivity().getResources().getDrawable(R.drawable.circle_green_dark),
                    getActivity().getResources().getDrawable(R.drawable.circle_green_light),
                    getActivity().getResources().getDrawable(R.drawable.circle_purple_dark),
                    getActivity().getResources().getDrawable(R.drawable.circle_purple_light),
                    getActivity().getResources().getDrawable(R.drawable.circle_red_dark),
                    getActivity().getResources().getDrawable(R.drawable.circle_red_light),
                    getActivity().getResources().getDrawable(R.drawable.circle_yellow_dark),
                    getActivity().getResources().getDrawable(R.drawable.circle_yellow_light) };

            //Create a new array with a list of all the library labels.
            final String[] labelsIdsArray = { "circle_blue_dark", "circle_blue_light", "circle_green_dark",
                    "circle_green_light", "circle_purple_dark", "circle_purple_light", "circle_red_dark",
                    "circle_red_light", "circle_yellow_dark", "circle_yellow_light" };

            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(R.string.music_library_label);
            ArrayList<String> labelTitles = new ArrayList<String>();
            labelTitles
                    .addAll(Arrays.asList(getActivity().getResources().getStringArray(R.array.library_labels)));
            builder.setAdapter(new LibraryLabelsAdapter(getActivity(), labelTitles), new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    libraryLabelID = labelsIdsArray[which];
                    labelButton.setImageDrawable(labelsArray[which]);

                }

            });

            builder.create().show();

        }

    });

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    //Set the dialog title.
    builder.setTitle(R.string.add_music_library);
    builder.setView(rootView);
    builder.setPositiveButton(R.string.ok, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int arg1) {
            String libraryName = musicLibraryName.getText().toString();

            Intent intent = new Intent(getActivity(), MusicLibraryEditorActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("LIBRARY_NAME", libraryName);
            bundle.putString("LIBRARY_ICON", libraryLabelID);
            intent.putExtras(bundle);
            startActivity(intent);

            dialog.dismiss();
            getActivity().finish();

        }

    });

    builder.setNegativeButton(R.string.cancel, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int arg1) {
            dialog.dismiss();
            getActivity().finish();

        }

    });

    return builder.create();
}