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.facebook.android.friendsmash.ScoreboardFragment.java

private void closeAndShowError(String error) {
    Bundle bundle = new Bundle();
    bundle.putString("error", error);

    Intent i = new Intent();
    i.putExtras(bundle);

    getActivity().setResult(Activity.RESULT_CANCELED, i);
    getActivity().finish();/*  w w w  .  j a v a2s.c o  m*/
}

From source file:be.evias.cloudLogin.FragmentNavigationDrawer.java

public void retrieveAndStoreUserObject() {
    new AsyncTask<String, Void, Intent>() {
        @Override/* ww w  . ja  va  2s. co m*/
        protected Intent doInBackground(String... params) {
            Bundle data = new Bundle();
            try {
                final String accountName = mPrefs.getString("cloudlogin_active_account_name", "");

                if (accountName.length() == 0)
                    throw new Exception("No active User Session found on this device.");

                mCurrentUser = sServerAuthenticate.getUserObject(mContext, accountName);

                if (mCurrentUser == null)
                    throw new Exception("Could not retrieve User Object (Server Error).");
            } catch (Exception e) {
                Log.d("cloudLogin",
                        "FragmentNavigationDrawer/retrieveAndStoreUserObject: getUserObject error.");
                e.printStackTrace();
            }

            final Intent res = new Intent();
            res.putExtras(data);
            return res;
        }

        @Override
        protected void onPostExecute(Intent intent) {
            if (mCurrentUser != null)
                initializeNavigationAdapter();
            else {
                Toast.makeText(getActivity(), mContext.getString(R.string.error_network), Toast.LENGTH_LONG)
                        .show();
            }
        }
    }.execute();
}

From source file:com.mirasense.scanditsdk.plugin.FullScreenPickerActivity.java

@Override
public void didScan(ScanSession session) {
    if (sPendingClose.get()) {
        // return if there is a pending close. Otherwise we might deadlock
        return;/*from w ww  . j av a2s  .  c o m*/
    }
    Bundle bundle = bundleForScanResult(session);
    if (!mContinuousMode) {
        mPickerStateMachine.switchToNextScanState(PickerStateMachine.PAUSED, session);
        final Intent intent = new Intent();
        bundle.putBoolean("waitForResult", false);
        intent.putExtras(bundle);
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                setResult(SCAN, intent);
                finish();
            }
        });
        return;
    }
    int nextState = ResultRelay.relayResult(bundle);
    mPickerStateMachine.switchToNextScanState(nextState, session);
    Marshal.rejectCodes(session, mRejectedCodeIds);
}

From source file:my.home.lehome.service.SendMsgIntentService.java

private void saveAndNotify(Intent intent, String result) {
    Context context = getApplicationContext();
    int rep_code = -1;
    String desc;//from   w w  w . j  a v  a 2  s  .  c  o m
    try {
        JSONObject jsonObject = new JSONObject(result);
        rep_code = jsonObject.getInt("code");
        desc = jsonObject.getString("desc");
    } catch (JSONException e) {
        e.printStackTrace();
        desc = context.getString(R.string.chat_error_json);
    }

    Messenger messenger;
    if (intent.hasExtra("messenger"))
        messenger = (Messenger) intent.getExtras().get("messenger");
    else
        messenger = null;

    Message repMsg = Message.obtain();
    repMsg.what = MSG_END_SENDING;

    ChatItem item = intent.getParcelableExtra("pass_item");
    ChatItem newItem = null;
    if (item != null) {
        if (rep_code == 200) {
            item.setState(Constants.CHATITEM_STATE_SUCCESS);
            DBStaticManager.updateChatItem(context, item);
        } else {
            if (rep_code == 415) {
                item.setState(Constants.CHATITEM_STATE_SUCCESS);
            } else {
                item.setState(Constants.CHATITEM_STATE_ERROR);
            }
            DBStaticManager.updateChatItem(context, item);

            newItem = new ChatItem();
            newItem.setContent(desc);
            newItem.setType(ChatItemConstants.TYPE_SERVER);
            newItem.setState(Constants.CHATITEM_STATE_ERROR); // always set true
            newItem.setDate(new Date());
            DBStaticManager.addChatItem(context, newItem);
        }
    } else {
        if (rep_code != 200) {
            Log.d(TAG, result);
            newItem = new ChatItem();
            newItem.setContent(getString(R.string.loc_send_error) + ":" + desc); // TODO - not only loc report
            newItem.setType(ChatItemConstants.TYPE_SERVER);
            newItem.setState(Constants.CHATITEM_STATE_SUCCESS); // always set true
            newItem.setDate(new Date());
            DBStaticManager.addChatItem(context, newItem);
        }
    }

    Log.d(TAG, "dequeue item: " + item);
    if (item == null)
        return;

    Bundle bundle = new Bundle();
    bundle.putParcelable("item", item);
    if (newItem != null)
        bundle.putParcelable("new_item", newItem);
    bundle.putInt("rep_code", rep_code);
    if (messenger != null) {
        repMsg.setData(bundle);
        try {
            messenger.send(repMsg);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    } else {
        Log.d(TAG, "messager is null, send broadcast instead:" + ACTION_SEND_MSG_END);
        Intent newIntent = new Intent(ACTION_SEND_MSG_END);
        newIntent.putExtras(bundle);
        sendBroadcast(newIntent);
    }
}

From source file:com.google.cloud.solutions.cloudadventure.GCMIntentService.java

/**
 * Called when a cloud message has been received.
 *//*from w  w w . jav  a 2 s  .  c om*/
@Override
public void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

    String messageType = gcm.getMessageType(intent);

    if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
        Log.i("GCMIntentService", "Received Msg Type:" + messageType);
        Log.i("GCMIntentService", "Received Msg : " + extras.toString());

        if (PING_REASON_FRIEND_INVITE.equals(intent.getStringExtra(GCM_PAYLOAD_PING_REASON))) {
            Log.i("GCMIntentService", "Received ping for friend invite.");
            Intent resultIntent = new Intent(this, ProfileActivity.class);
            resultIntent.putExtras(intent);
            generateNotification(resultIntent, ProfileActivity.class);
        } else if (PING_REASON_FRIEND_ACCEPT.equals(intent.getStringExtra(GCM_PAYLOAD_PING_REASON))) {
            Log.i("GCMIntentService", "Received ping for friend acceptance.");
            Intent resultIntent = new Intent(this, ProfileActivity.class);
            resultIntent.putExtras(intent);
            generateNotification(resultIntent, ProfileActivity.class);
        } else if (PING_REASON_GAME_INVITE.equals(intent.getStringExtra(GCM_PAYLOAD_PING_REASON))) {
            Log.i("GCMIntentService", "Received ping for game invite.");
            Intent resultIntent = new Intent(this, GameActivity.class);
            resultIntent.putExtras(intent);
            resultIntent.putExtra(Constants.GAME_ENTRANCE_ACTION_INTENT_EXTRA_KEY,
                    Constants.GAME_ENTRANCE_ACTION_NOTIFICATION);
            generateNotification(resultIntent, GameActivity.class);
        } else if (PING_REASON_GAME_STARTED.equals(intent.getStringExtra(GCM_PAYLOAD_PING_REASON))) {
            Log.i("GCMIntentService", "Received ping for game start.");
            Intent messageIntent = new Intent(BROADCAST_ON_MESSAGE_GAME_START);
            messageIntent.putExtras(intent);
            LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
        } else if (PING_REASON_GAME_DESTROYED.equals(intent.getStringExtra(GCM_PAYLOAD_PING_REASON))) {
            Log.i("GCMIntentService", "Received ping for game destroy.");
            Intent messageIntent = new Intent(BROADCAST_ON_MESSAGE_GAME_DESTROY);
            messageIntent.putExtras(intent);
            LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
        } else if (PING_REASON_GAME_ENDED.equals(intent.getStringExtra(GCM_PAYLOAD_PING_REASON))) {
            Log.i("GCMIntentService", "Received ping for game end.");
            Intent messageIntent = new Intent(BROADCAST_ON_MESSAGE_GAME_END);
            messageIntent.putExtras(intent);
            LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
        } else if (PING_REASON_PLAYER_JOINED.equals(intent.getStringExtra(GCM_PAYLOAD_PING_REASON))) {
            Log.i("GCMIntentService", "Received ping for game join.");
            Intent messageIntent = new Intent(BROADCAST_ON_MESSAGE_PLAYER_JOIN);
            messageIntent.putExtras(intent);
            LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
        } else if (PING_REASON_PLAYER_LEFT.equals(intent.getStringExtra(GCM_PAYLOAD_PING_REASON))) {
            Log.i("GCMIntentService", "Received ping for game leave.");
            Intent messageIntent = new Intent(BROADCAST_ON_MESSAGE_PLAYER_LEAVE);
            messageIntent.putExtras(intent);
            LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
        } else if (PING_REASON_PLAYER_END_STATS.equals(intent.getStringExtra(GCM_PAYLOAD_PING_REASON))) {
            Log.i("GCMIntentService", "Received ping for player end stats.");
            Intent messageIntent = new Intent(BROADCAST_ON_MESSAGE_PLAYER_END_STATS);
            messageIntent.putExtras(intent);
            LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
        }
    }
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.andrewchelladurai.simplebible.SearchFragment.java

private void bookmarkButtonClicked() {
    Collection<SearchResultList.SearchResultItem> items = SearchResultList.getSelectedItems();
    if (items.isEmpty()) {
        Log.e(TAG, "bookmarkButtonClicked: returning - No Selected Entries :\n"
                + getString(R.string.how_am_i_here));
        return;//w w  w . j a v  a 2s  .co m
    }
    String reference = Utilities.prepareBookmarkReferenceFromSearchResults(items);
    if (reference.isEmpty()) {
        Log.e(TAG, "bookmarkButtonClicked: returning - reference is empty");
        return;
    }
    String returnValue = mPresenter.bookmarkButtonClicked(reference);
    Bundle args = new Bundle();
    args.putString(BookmarkActivityOperations.ARG_REFERENCE, reference);
    switch (returnValue) {
    case BookmarkActivityOperations.VIEW:
        args.putString(BookmarkActivityOperations.ARG_MODE, BookmarkActivityOperations.VIEW);
        break;
    case BookmarkActivityOperations.CREATE:
    default:
        args.putString(BookmarkActivityOperations.ARG_MODE, BookmarkActivityOperations.CREATE);
        Log.w(TAG, "bookmarkButtonClicked: " + getString(R.string.how_am_i_here));
        Log.w(TAG, "bookmarkButtonClicked: setting ARG_MODE = CREATE");
    }
    Intent intent = new Intent(getContext(), BookmarkActivity.class);
    intent.putExtras(args);
    startActivity(intent);
}

From source file:com.boko.vimusic.ui.fragments.PlaylistFragment.java

/**
 * {@inheritDoc}//from  ww  w .  j a  v  a2 s.  com
 */
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
    final Bundle bundle = new Bundle();
    mPlaylist = mAdapter.getItem(position);
    String playlistName;
    // Favorites list
    if (position == 0) {
        playlistName = getString(R.string.playlist_favorites);
        bundle.putString(Config.MIME_TYPE, getString(R.string.playlist_favorites));
        // Last added
    } else if (position == 1) {
        playlistName = getString(R.string.playlist_last_added);
        bundle.putString(Config.MIME_TYPE, getString(R.string.playlist_last_added));
    } else {
        // User created
        playlistName = mPlaylist.getName();
        bundle.putString(Config.MIME_TYPE, MediaStore.Audio.Playlists.CONTENT_TYPE);
        if (mPlaylist.getId() != null) {
            bundle.putString(Config.ID, mPlaylist.getId());
        }
    }

    bundle.putString(Config.NAME, playlistName);

    // Create the intent to launch the profile activity
    final Intent intent = new Intent(getActivity(), ProfileActivity.class);
    intent.putExtras(bundle);
    startActivity(intent);
}

From source file:com.andrew.apollo.ui.fragments.PlaylistFragment.java

/**
 * {@inheritDoc}/*from w w  w .  j  av  a2 s .  co m*/
 */
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
    final Bundle bundle = new Bundle();
    mPlaylist = mAdapter.getItem(position);
    String playlistName;
    // Favorites list
    if (position == 0) {
        playlistName = getString(R.string.playlist_favorites);
        bundle.putString(Config.MIME_TYPE, getString(R.string.playlist_favorites));
        // Last added
    } else if (position == 1) {
        playlistName = getString(R.string.playlist_last_added);
        bundle.putString(Config.MIME_TYPE, getString(R.string.playlist_last_added));
    } else {
        // User created
        playlistName = mPlaylist.mPlaylistName;
        bundle.putString(Config.MIME_TYPE, MediaStore.Audio.Playlists.CONTENT_TYPE);
        bundle.putLong(Config.ID, Long.valueOf(mPlaylist.mPlaylistId));
    }

    bundle.putString(Config.NAME, playlistName);

    // Create the intent to launch the profile activity
    final Intent intent = new Intent(getSherlockActivity(), ProfileActivity.class);
    intent.putExtras(bundle);
    startActivity(intent);
}

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

@Override
protected void onResume() {
    super.onResume();

    // Setup broadcast receiver for feedback from service.
    mServiceMessageReceiver = new ServiceMessageReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(ProfileOwnerProvisioningService.ACTION_PROVISIONING_SUCCESS);
    filter.addAction(ProfileOwnerProvisioningService.ACTION_PROVISIONING_ERROR);
    filter.addAction(ProfileOwnerProvisioningService.ACTION_PROVISIONING_CANCELLED);
    LocalBroadcastManager.getInstance(this).registerReceiver(mServiceMessageReceiver, filter);

    // Start service async to make sure the UI is loaded first.
    final Handler handler = new Handler(getMainLooper());
    handler.post(new Runnable() {
        @Override/*  w ww. j  av  a 2 s.  c  o m*/
        public void run() {
            Intent intent = new Intent(ProfileOwnerProvisioningActivity.this,
                    ProfileOwnerProvisioningService.class);
            intent.putExtras(getIntent());
            startService(intent);
        }
    });
}

From source file:br.com.moviecreator.views.home.HomeFragment.java

@Nullable
@Override/*  ww  w  .  j  av a  2 s.c om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.home_app_bar, container, false);

    adapter = new MoviesAdapter(new ArrayList<Movie>(), LayoutInflater.from(getActivity()),
            new ItemClickListener<Movie>() {
                @Override
                public void onItemClick(Movie movie) {
                    Bundle extra = new Bundle();
                    extra.putSerializable(DetailsActivity.DETAILS_EXTRA, movie);

                    Intent intent = new Intent(getActivity(), DetailsActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    intent.putExtras(extra);

                    getActivity().startActivity(intent);
                }
            });

    gridLayoutManager = new GridLayoutManager(getActivity(), 2);
    gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);

    boryLayout = (LinearLayout) rootView.findViewById(R.id.home_bory_search);
    swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh);
    swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimary,
            R.color.colorPrimaryDark);
    swipeRefreshLayout.setEnabled(false);

    RecyclerView recyclerViewMovies = (RecyclerView) rootView.findViewById(R.id.movies_result_list);
    recyclerViewMovies.setHasFixedSize(true);
    recyclerViewMovies.setLayoutManager(gridLayoutManager);
    recyclerViewMovies.setAdapter(adapter);
    recyclerViewMovies.addItemDecoration(new SpacesItemDecoration(10));

    boryLayout.setVisibility(View.VISIBLE);
    swipeRefreshLayout.setVisibility(View.GONE);

    return rootView;
}