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:gov.wa.wsdot.android.wsdot.ui.TwitterFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    Bundle b = new Bundle();
    Intent intent = new Intent(getActivity(), TwitterDetailsActivity.class);
    b.putString("userName", twitterItems.get(position).getUserName());
    b.putString("createdAt", twitterItems.get(position).getCreatedAt());
    b.putString("text", twitterItems.get(position).getText());
    b.putString("htmlText", twitterItems.get(position).getFormatedHtmlText());
    intent.putExtras(b);

    startActivity(intent);//from   w ww.j  ava 2s. co  m
}

From source file:li.barter.fragments.AddOrEditBookFragment.java

@Override
public void onQueryComplete(final int token, final Object cookie, final Cursor cursor) {
    if (token == QueryTokens.LOAD_BOOK_DETAIL_FOR_EDIT) {
        if (cursor.moveToFirst()) {

            /* Force a crash if trying to edit someone else's book. This should not happen in
             production *//*  ww w.  j  a  v  a 2  s. c o  m*/
            final String userId = cursor.getString(cursor.getColumnIndex(DatabaseColumns.USER_ID));

            if (!userId.equals(AppConstants.UserInfo.INSTANCE.getId())) {
                throw new RuntimeException("Trying to edit someone else's book!");
            }
            mIsbnEditText.setText(cursor.getString(cursor.getColumnIndex(DatabaseColumns.ISBN_10)));
            mTitleEditText.setTextWithFilter(cursor.getString(cursor.getColumnIndex(DatabaseColumns.TITLE)),
                    false);
            mAuthorEditText.setText(cursor.getString(cursor.getColumnIndex(DatabaseColumns.AUTHOR)));
            mDescriptionEditText.setText(cursor.getString(cursor.getColumnIndex(DatabaseColumns.DESCRIPTION)));

            mPublicationYear = cursor.getString(cursor.getColumnIndex(DatabaseColumns.PUBLICATION_YEAR));

            mImage_Url = cursor.getString(cursor.getColumnIndex(DatabaseColumns.IMAGE_URL));

            final String value = cursor.getString(cursor.getColumnIndex(DatabaseColumns.VALUE));

            if (!TextUtils.isEmpty(value)) {

                mSellPriceEditText.setVisibility(View.VISIBLE);
                mSellPriceEditText.setText(value);
            }

            final String barterType = cursor.getString(cursor.getColumnIndex(DatabaseColumns.BARTER_TYPE));

            if (!TextUtils.isEmpty(barterType)) {
                setBarterCheckboxes(barterType);
            }
        }

        cursor.close();
    } else if (token == QueryTokens.LOAD_BOOK_DETAIL_FOR_OPEN) {

        if (cursor.moveToFirst()) {

            final Bundle showBooksArgs = Utils.cursorToBundle(cursor);
            final Intent resultIntent = new Intent();
            resultIntent.putExtras(showBooksArgs);
            getActivity().setResult(ActionBarActivity.RESULT_OK, resultIntent);
            getActivity().finish();
        }
    }
}

From source file:com.bonsai.wallet32.PasscodeActivity.java

private void setupComplete() {

    Intent intent;//from w  w w . j ava 2  s.co m

    // In all cases we are effectively logged in now.
    mApp.setLoggedIn();

    switch (mAction) {
    case ACTION_CREATE:
        // Create the wallet.
        WalletUtil.createWallet(getApplicationContext());

        // Spin up the WalletService.
        Intent svcintent = new Intent(this, WalletService.class);
        Bundle bundle = new Bundle();
        bundle.putString("SyncState", "CREATED");
        svcintent.putExtras(bundle);
        startService(svcintent);

        intent = new Intent(this, ViewSeedActivity.class);
        Bundle bundle2 = new Bundle();
        bundle2.putBoolean("showDone", true);
        intent.putExtras(bundle2);
        startActivity(intent);
        break;

    case ACTION_RESTORE:
        intent = new Intent(this, RestoreWalletActivity.class);
        startActivity(intent);
        break;

    case ACTION_PAIR:
        intent = new Intent(this, PairWalletActivity.class);
        startActivity(intent);
        break;

    case ACTION_CHANGE:
        // We're all set, back to where we came from.
        break;

    default:
        // Shouldn't ever get here.
        String msg = "unexpected action in setupComplete";
        mLogger.error(msg);
        throw new RuntimeException(msg);
    }

    // And we're done here ...
    finish();
}

From source file:com.arcusapp.soundbox.fragment.PlayFragment.java

@Override
public void onClick(View v) {
    if (currentSong == null || mediaService == null) {
        return;//from   w ww  .  java 2 s . c  o  m
    }

    if (v.getId() == R.id.btnPlayPause) {
        mediaService.playAndPause();
    } else if (v.getId() == R.id.btnPanel) {
        if (mIsPanelExpanded) {
            Intent intent = new Intent();
            intent.setAction(SoundBoxApplication.ACTION_SONGSLIST_ACTIVITY);

            Bundle mExtras = new Bundle();
            List<String> songsID = mediaService.getSongsIDList();
            mExtras.putStringArrayList(BundleExtra.SONGS_ID_LIST, (ArrayList<String>) songsID);
            String currentSongID = mediaService.getCurrentSong().getID();
            mExtras.putString(BundleExtra.CURRENT_ID, currentSongID);

            intent.putExtras(mExtras);
            startActivity(intent);
        } else {
            mediaService.playAndPause();
        }
    } else if (v.getId() == R.id.btnPrevSong) {
        mediaService.playPreviousSong();

    } else if (v.getId() == R.id.btnNextSong) {
        mediaService.playNextSong();
    } else if (v.getId() == R.id.btnSwitchRandom) {
        mediaService.changeRandomState();
        //Toast.makeText(this, randomStateToText(mediaService.getRandomState()), Toast.LENGTH_SHORT).show();
    } else if (v.getId() == R.id.btnSwitchRepeat) {
        mediaService.changeRepeatState();
        //Toast.makeText(this, repeatStateToText(mediaService.getRepeatState()), Toast.LENGTH_SHORT).show();
    }
}

From source file:au.com.wallaceit.reddinator.Rservice.java

@Override
public RemoteViews getViewAt(int position) {
    RemoteViews row;//from w  w  w.  ja  v  a2s .  co m
    if (position > data.length()) {
        return null; //  prevent errornous views
    }
    // check if its the last view and return loading view instead of normal row
    if (position == data.length()) {
        // build load more item
        //System.out.println("load more getViewAt("+position+") firing");
        RemoteViews loadmorerow = new RemoteViews(mContext.getPackageName(), R.layout.listrowloadmore);
        if (endOfFeed) {
            loadmorerow.setTextViewText(R.id.loadmoretxt, "There's nothing more here");
        } else {
            loadmorerow.setTextViewText(R.id.loadmoretxt, "Load more...");
        }
        loadmorerow.setTextColor(R.id.loadmoretxt, themeColors[0]);
        Intent i = new Intent();
        Bundle extras = new Bundle();
        extras.putString(WidgetProvider.ITEM_ID, "0"); // zero will be an indicator in the onreceive function of widget provider if its not present it forces a reload
        i.putExtras(extras);
        loadmorerow.setOnClickFillInIntent(R.id.listrowloadmore, i);
        return loadmorerow;
    } else {
        // build normal item
        String title = "";
        String url = "";
        String permalink = "";
        String thumbnail = "";
        String domain = "";
        String id = "";
        int score = 0;
        int numcomments = 0;
        boolean nsfw = false;
        try {
            JSONObject tempobj = data.getJSONObject(position).getJSONObject("data");
            title = tempobj.getString("title");
            //userlikes = tempobj.getString("likes");
            domain = tempobj.getString("domain");
            id = tempobj.getString("name");
            url = tempobj.getString("url");
            permalink = tempobj.getString("permalink");
            thumbnail = (String) tempobj.get("thumbnail"); // we have to call get and cast cause its not in quotes
            score = tempobj.getInt("score");
            numcomments = tempobj.getInt("num_comments");
            nsfw = tempobj.getBoolean("over_18");
        } catch (JSONException e) {
            e.printStackTrace();
            // return null; // The view is invalid;
        }
        // create remote view from specified layout
        if (bigThumbs) {
            row = new RemoteViews(mContext.getPackageName(), R.layout.listrowbigthumb);
        } else {
            row = new RemoteViews(mContext.getPackageName(), R.layout.listrow);
        }
        // build view
        row.setTextViewText(R.id.listheading, Html.fromHtml(title).toString());
        row.setFloat(R.id.listheading, "setTextSize", Integer.valueOf(titleFontSize)); // use for compatibility setTextViewTextSize only introduced in API 16
        row.setTextColor(R.id.listheading, themeColors[0]);
        row.setTextViewText(R.id.sourcetxt, domain);
        row.setTextColor(R.id.sourcetxt, themeColors[3]);
        row.setTextColor(R.id.votestxt, themeColors[4]);
        row.setTextColor(R.id.commentstxt, themeColors[4]);
        row.setTextViewText(R.id.votestxt, String.valueOf(score));
        row.setTextViewText(R.id.commentstxt, String.valueOf(numcomments));
        row.setInt(R.id.listdivider, "setBackgroundColor", themeColors[2]);
        row.setViewVisibility(R.id.nsfwflag, nsfw ? TextView.VISIBLE : TextView.GONE);
        // add extras and set click intent
        Intent i = new Intent();
        Bundle extras = new Bundle();
        extras.putString(WidgetProvider.ITEM_ID, id);
        extras.putInt("itemposition", position);
        extras.putString(WidgetProvider.ITEM_URL, url);
        extras.putString(WidgetProvider.ITEM_PERMALINK, permalink);
        i.putExtras(extras);
        row.setOnClickFillInIntent(R.id.listrow, i);
        // load thumbnail if they are enabled for this widget
        if (loadThumbnails) {
            // load big image if preference is set
            if (!thumbnail.equals("")) { // check for thumbnail; self is used to display the thinking logo on the reddit site, we'll just show nothing for now
                if (thumbnail.equals("nsfw") || thumbnail.equals("self") || thumbnail.equals("default")) {
                    int resource = 0;
                    switch (thumbnail) {
                    case "nsfw":
                        resource = R.drawable.nsfw;
                        break;
                    case "default":
                    case "self":
                        resource = R.drawable.self_default;
                        break;
                    }
                    row.setImageViewResource(R.id.thumbnail, resource);
                    row.setViewVisibility(R.id.thumbnail, View.VISIBLE);
                    //System.out.println("Loading default image: "+thumbnail);
                } else {
                    Bitmap bitmap;
                    String fileurl = mContext.getCacheDir() + "/thumbcache-" + appWidgetId + "/" + id + ".png";
                    // check if the image is in cache
                    if (new File(fileurl).exists()) {
                        bitmap = BitmapFactory.decodeFile(fileurl);
                        saveImageToStorage(bitmap, id);
                    } else {
                        // download the image
                        bitmap = loadImage(thumbnail);
                    }
                    if (bitmap != null) {
                        row.setImageViewBitmap(R.id.thumbnail, bitmap);
                        row.setViewVisibility(R.id.thumbnail, View.VISIBLE);
                    } else {
                        // row.setImageViewResource(R.id.thumbnail, android.R.drawable.stat_notify_error); for later
                        row.setViewVisibility(R.id.thumbnail, View.GONE);
                    }
                }
            } else {
                row.setViewVisibility(R.id.thumbnail, View.GONE);
            }
        } else {
            row.setViewVisibility(R.id.thumbnail, View.GONE);
        }
        // hide info bar if options set
        if (hideInf) {
            row.setViewVisibility(R.id.infbox, View.GONE);
        } else {
            row.setViewVisibility(R.id.infbox, View.VISIBLE);
        }
    }
    //System.out.println("getViewAt("+position+");");
    return row;
}

From source file:com.facebook.SessionTests.java

@SmallTest
@MediumTest//from   www.j ava2  s. co m
@LargeTest
public void testOpenSessionWithNativeLinkingIntent() {
    String token = "A token less unique than most";

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.putExtras(getNativeLinkingExtras(token));

    SessionStatusCallbackRecorder statusRecorder = new SessionStatusCallbackRecorder();
    MockTokenCachingStrategy cache = new MockTokenCachingStrategy(null, DEFAULT_TIMEOUT_MILLISECONDS);
    ScriptedSession session = createScriptedSessionOnBlockerThread(cache);

    assertEquals(SessionState.CREATED, session.getState());

    AccessToken accessToken = AccessToken.createFromNativeLinkingIntent(intent);
    assertNotNull(accessToken);
    session.open(accessToken, statusRecorder);

    statusRecorder.waitForCall(session, SessionState.OPENED, null);

    assertEquals(token, session.getAccessToken());
    // Expiration time should be 3600s after now (allow 5s variation for test execution time)
    long delta = session.getExpirationDate().getTime() - new Date().getTime();
    assertTrue(Math.abs(delta - 3600 * 1000) < 5000);
    assertEquals(0, session.getPermissions().size());
    assertEquals(Utility.getMetadataApplicationId(getActivity()), session.getApplicationId());

    // Verify we get a close callback.
    session.close();
    statusRecorder.waitForCall(session, SessionState.CLOSED, null);

    assertFalse(cache.getSavedState() == null);

    // Wait a bit so we can fail if any unexpected calls arrive on the
    // recorder.
    stall(STRAY_CALLBACK_WAIT_MILLISECONDS);
    statusRecorder.close();
}

From source file:com.example.mynsocial.BluetoothChat.java

public void FinalResult() {
    loginPreferences = getSharedPreferences("loginPrefs", MODE_PRIVATE);
    loginPrefsEditor = loginPreferences.edit();
    if (myscore > youscore) {
        fbcaption = "Win";
        wincount = loginPreferences.getInt("win", 0);
        loginPrefsEditor.putInt("win", wincount + 1);
        loginPrefsEditor.commit();/*from  ww w .j  a v a2s . c  o  m*/
        new SaveProductDetails().execute();
        Log.e(TAG, "+++ i win+++");
    } else if (myscore < youscore) {
        fbcaption = "Lose";
        Log.e(TAG, "+++ i lost +++");
    } else {
        fbcaption = "Deuce";
    }

    finalscore = myscore + ":" + youscore;
    //       publishFeedDialog();

    Intent intent = new Intent();
    intent.setClass(BluetoothChat.this, Result.class);
    Bundle bundle = new Bundle();
    if (fbcaption.equals("Win")) {
        bundle.putString("fbcaption", "I win the game!");
        bundle.putString("score", finalscore);
        intent.putExtras(bundle);
    } else if (fbcaption.equals("Lose")) {
        bundle.putString("fbcaption", "I lose the game!");
        bundle.putString("score", finalscore);
        intent.putExtras(bundle);
    } else if (fbcaption.equals("Deuce")) {
        bundle.putString("fbcaption", "We deuce!");
        bundle.putString("score", finalscore);
        intent.putExtras(bundle);
    }
    //BluetoothChat.this.finish();
    startActivity(intent);
}

From source file:com.facebook.SessionTests.java

@SmallTest
@MediumTest//from   w  ww  .jav a2  s . c  om
@LargeTest
public void testOpenActiveSessionWithNativeLinkingIntent() {
    Session activeSession = Session.getActiveSession();
    if (activeSession != null) {
        activeSession.closeAndClearTokenInformation();
    }

    SharedPreferencesTokenCachingStrategy tokenCache = new SharedPreferencesTokenCachingStrategy(getActivity());
    assertEquals(0, tokenCache.load().size());

    String token = "A token less unique than most";

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.putExtras(getNativeLinkingExtras(token));

    SessionStatusCallbackRecorder statusRecorder = new SessionStatusCallbackRecorder();

    AccessToken accessToken = AccessToken.createFromNativeLinkingIntent(intent);
    assertNotNull(accessToken);
    Session session = Session.openActiveSessionWithAccessToken(getActivity(), accessToken, statusRecorder);
    assertEquals(session, Session.getActiveSession());

    statusRecorder.waitForCall(session, SessionState.OPENED, null);

    assertNotSame(0, tokenCache.load().size());

    assertEquals(token, session.getAccessToken());
    // Expiration time should be 3600s after now (allow 5s variation for test execution time)
    long delta = session.getExpirationDate().getTime() - new Date().getTime();
    assertTrue(Math.abs(delta - 3600 * 1000) < 5000);
    assertEquals(0, session.getPermissions().size());
    assertEquals(Utility.getMetadataApplicationId(getActivity()), session.getApplicationId());

    // Verify we get a close callback.
    session.close();
    statusRecorder.waitForCall(session, SessionState.CLOSED, null);

    // Wait a bit so we can fail if any unexpected calls arrive on the
    // recorder.
    stall(STRAY_CALLBACK_WAIT_MILLISECONDS);
    statusRecorder.close();
}

From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java

private void init_map_buttons() {
    Button from_map_button = (Button) findViewById(R.id.from_map_button);
    from_map_button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), RbmMapActivity.class);
            Bundle b = new Bundle();
            b.putBoolean("set_result", true);
            intent.putExtras(b);
            startActivityForResult(intent, ACTIVITY_FROM);
        }//from  ww w . j a  v a  2 s. c  o m
    });

    Button to_map_button = (Button) findViewById(R.id.to_map_button);
    to_map_button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), RbmMapActivity.class);
            Bundle b = new Bundle();
            b.putBoolean("set_result", true);
            intent.putExtras(b);
            startActivityForResult(intent, ACTIVITY_TO);
        }
    });
}

From source file:com.androzic.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Log.e(TAG, "onNewIntent()");
    if (intent.hasExtra(LAUNCH_ACTIVITY)) {
        Serializable object = intent.getExtras().getSerializable(LAUNCH_ACTIVITY);
        if (Class.class.isInstance(object)) {
            Intent launch = new Intent(this, (Class<?>) object);
            launch.putExtras(intent);
            launch.removeExtra(LAUNCH_ACTIVITY);
            startActivity(launch);//from   ww w.j  a  v  a  2 s. com
        }
    } else if (intent.hasExtra(SHOW_FRAGMENT)) {
        Serializable object = intent.getExtras().getSerializable(SHOW_FRAGMENT);
        if (Class.class.isInstance(object)) {
            @SuppressWarnings("rawtypes")
            String name = ((Class) object).getName();
            Fragment f = Fragment.instantiate(this, name);
            intent.removeExtra(SHOW_FRAGMENT);
            f.setArguments(intent.getExtras());
            if (DialogFragment.class.isInstance(f))
                ((DialogFragment) f).show(getSupportFragmentManager(), "show");
            else
                addFragment(f, name);
        }
    } else if (intent.hasExtra("lat") && intent.hasExtra("lon")) {
        application.ensureVisible(intent.getExtras().getDouble("lat"), intent.getExtras().getDouble("lon"));
        selectItem(0);
    }
}