Example usage for android.content Intent getBundleExtra

List of usage examples for android.content Intent getBundleExtra

Introduction

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

Prototype

public Bundle getBundleExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:org.mklab.mikity.android.MainActivity.java

/**
 * ?????????// w ww. j  a  va2 s.  c o  m
 */
private void startIntentByExternalActivity() {
    final String intentPath = "path"; //$NON-NLS-1$
    final String intentDataPath = "data"; //$NON-NLS-1$

    final Intent intent = getIntent();
    if (intent.getBundleExtra(intentPath) == null) {
        return;
    }

    final Bundle bundle = intent.getBundleExtra(intentPath);
    if (bundle.getParcelable(intentPath) == null) {
        return;
    }

    final Uri modelPath = bundle.getParcelable(intentPath);
    loadModelData(modelPath);
    if (bundle.getParcelable(intentDataPath) == null) {
        return;
    }

    final Uri sourcePath = bundle.getParcelable(intentDataPath);
    final String sourceId = intent.getStringExtra("sourceId"); //$NON-NLS-1$
    loadSourceData(sourcePath, sourceId);
}

From source file:com.dnielfe.manager.Browser.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_browser);

    Intent intent = getIntent();

    if (savedInstanceState == null) {
        savedInstanceState = intent.getBundleExtra(EXTRA_SAVED_STATE);
    }/*from  w  w  w.j a v a2 s. com*/

    init(intent);
    initDirectory(savedInstanceState, intent);
}

From source file:org.arakhne.afc.ui.android.filechooser.FileChooserActivity.java

/**
 * {@inheritDoc}//from ww w. j av  a 2s.c o m
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    this.activityOptions = intent.getBundleExtra(ACTIVITY_OPTIONS);

    this.path = getFileParameter(SAVED_PATH_NAME, null, this.activityOptions, savedInstanceState);

    if (this.path == null) {
        SharedPreferences preferences = getPreferences(DEFAULT_KEYS_SEARCH_LOCAL);
        String filePath = preferences.getString(PREFERENCE_FILE_PATH, null);
        if (filePath != null && !filePath.isEmpty()) {
            this.path = new File(filePath);
            if (!this.path.isDirectory()) {
                this.path = this.path.getParentFile();
            }
        }
        if (this.path == null) {
            this.path = Environment.getExternalStorageDirectory();
        }
    }

    this.fileFilter = getFileFilterParameter(SAVED_FILE_FILTER, null, this.activityOptions, savedInstanceState);

    this.iconSelector = getIconSelectorParameter(SAVED_ICON_SELECTOR, null, this.activityOptions,
            savedInstanceState);

    if (this.activityOptions != null) {
        this.isOpen = this.activityOptions.getBoolean(SAVED_IS_OPEN,
                savedInstanceState != null ? savedInstanceState.getBoolean(SAVED_IS_OPEN, true) : true);
    }

    String basename = null;
    if (!this.isOpen && !this.path.isDirectory()) {
        basename = this.path.getName();
    }

    while (this.path != null && !this.path.isDirectory()) {
        this.path = this.path.getParentFile();
    }

    if (this.path == null) {
        this.path = Environment.getExternalStorageDirectory();
    }

    if (this.isOpen) {
        setContentView(R.layout.filechooser_open);
    } else {
        setContentView(R.layout.filechooser_save);
        EditText editor = (EditText) findViewById(R.id.fileChooserFilenameField);
        if (basename != null)
            editor.setText(basename);
        editor.addTextChangedListener(new Listener());
    }

    this.fragmentManager = getSupportFragmentManager();
    this.fragmentManager.addOnBackStackChangedListener(this);

    setTitle(this.path.getAbsolutePath());

    // Start to listen on directory changes.
    FileListFragment explorerFragment = FileListFragment.newInstance(this.path, this.fileFilter,
            this.iconSelector);
    FragmentTransaction transaction = this.fragmentManager.beginTransaction();
    transaction.add(R.id.fileChooserExplorerFragment, explorerFragment).commit();
}

From source file:com.ez.gallery.ucrop.UCropActivity.java

/**
 * This method extracts {@link com.ez.gallery.ucrop.UCrop.Options #optionsBundle} from incoming intent
 * and setups Activity, {@link OverlayView} and {@link CropImageView} properly.
 *//*from   w ww .j a v  a2 s.co  m*/
@SuppressWarnings("deprecation")
private void processOptions(@NonNull Intent intent) {
    Bundle optionsBundle = intent.getBundleExtra(UCrop.EXTRA_OPTIONS);
    if (optionsBundle != null) {
        // Bitmap compression options
        String compressionFormatName = optionsBundle.getString(UCrop.Options.EXTRA_COMPRESSION_FORMAT_NAME);
        Bitmap.CompressFormat compressFormat = null;
        if (!TextUtils.isEmpty(compressionFormatName)) {
            compressFormat = Bitmap.CompressFormat.valueOf(compressionFormatName);
        }
        mCompressFormat = (compressFormat == null) ? DEFAULT_COMPRESS_FORMAT : compressFormat;

        mCompressQuality = optionsBundle.getInt(UCrop.Options.EXTRA_COMPRESSION_QUALITY,
                UCropActivity.DEFAULT_COMPRESS_QUALITY);

        // Gestures options
        int[] allowedGestures = optionsBundle.getIntArray(UCrop.Options.EXTRA_ALLOWED_GESTURES);
        if (allowedGestures != null && allowedGestures.length == TABS_COUNT) {
            mAllowedGestures = allowedGestures;
        }

        // Crop image view options
        mGestureCropImageView.setMaxBitmapSize(optionsBundle.getInt(UCrop.Options.EXTRA_MAX_BITMAP_SIZE,
                CropImageView.DEFAULT_MAX_BITMAP_SIZE));
        mGestureCropImageView.setMaxScaleMultiplier(optionsBundle.getFloat(
                UCrop.Options.EXTRA_MAX_SCALE_MULTIPLIER, CropImageView.DEFAULT_MAX_SCALE_MULTIPLIER));
        mGestureCropImageView.setImageToWrapCropBoundsAnimDuration(
                optionsBundle.getInt(UCrop.Options.EXTRA_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION,
                        CropImageView.DEFAULT_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION));

        // Overlay view options
        mOverlayView.setDimmedColor(optionsBundle.getInt(UCrop.Options.EXTRA_DIMMED_LAYER_COLOR,
                getResources().getColor(R.color.ucrop_color_default_dimmed)));
        mOverlayView.setOvalDimmedLayer(optionsBundle.getBoolean(UCrop.Options.EXTRA_OVAL_DIMMED_LAYER,
                OverlayView.DEFAULT_OVAL_DIMMED_LAYER));

        mOverlayView.setShowCropFrame(optionsBundle.getBoolean(UCrop.Options.EXTRA_SHOW_CROP_FRAME,
                OverlayView.DEFAULT_SHOW_CROP_FRAME));
        mOverlayView.setCropFrameColor(optionsBundle.getInt(UCrop.Options.EXTRA_CROP_FRAME_COLOR,
                getResources().getColor(R.color.ucrop_color_default_crop_frame)));
        mOverlayView.setCropFrameStrokeWidth(optionsBundle.getInt(UCrop.Options.EXTRA_CROP_FRAME_STROKE_WIDTH,
                getResources().getDimensionPixelSize(R.dimen.ucrop_default_crop_frame_stoke_width)));

        mOverlayView.setShowCropGrid(optionsBundle.getBoolean(UCrop.Options.EXTRA_SHOW_CROP_GRID,
                OverlayView.DEFAULT_SHOW_CROP_GRID));
        mOverlayView.setCropGridRowCount(optionsBundle.getInt(UCrop.Options.EXTRA_CROP_GRID_ROW_COUNT,
                OverlayView.DEFAULT_CROP_GRID_ROW_COUNT));
        mOverlayView.setCropGridColumnCount(optionsBundle.getInt(UCrop.Options.EXTRA_CROP_GRID_COLUMN_COUNT,
                OverlayView.DEFAULT_CROP_GRID_COLUMN_COUNT));
        mOverlayView.setCropGridColor(optionsBundle.getInt(UCrop.Options.EXTRA_CROP_GRID_COLOR,
                getResources().getColor(R.color.ucrop_color_default_crop_grid)));
        mOverlayView.setCropGridStrokeWidth(optionsBundle.getInt(UCrop.Options.EXTRA_CROP_GRID_STROKE_WIDTH,
                getResources().getDimensionPixelSize(R.dimen.ucrop_default_crop_grid_stoke_width)));
    }
}

From source file:com.example.leandromaguna.myapp.Presentation.PlacesMap.PlacesMapActivity.java

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

    if (requestCode == REQUEST_PLACE) {
        if (resultCode == RESULT_OK) {
            Log.i(TAG, "REQUEST_PLACE/RESULT_OK");
            //Agrego marker a la lista
            Bundle newPlace = data.getBundleExtra("savedPlace");
            MarkerOptions newMarker = new MarkerOptions().position((LatLng) newPlace.get("position"))
                    .title((String) newPlace.get("title")).snippet((String) newPlace.get("description"));
            markers.add(newMarker);//from   w w w.j  ava 2  s.  c o m

            setMarkersOnMap();

        } else {
            Log.i(TAG, "REQUEST_PLACE/ELSE");
        }
    }
}

From source file:com.koushikdutta.superuser.FragmentLog.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    //header = (LinearLayout) getActivity().findViewById(R.id.header);

    ImageView icon = (ImageView) getActivity().findViewById(R.id.icon);

    TextView title, subtitle, request, command;

    title = (TextView) getActivity().findViewById(R.id.title);
    subtitle = (TextView) getActivity().findViewById(R.id.subtitle);
    request = (TextView) getActivity().findViewById(R.id.request);
    command = (TextView) getActivity().findViewById(R.id.command);

    Intent intent = getActivity().getIntent();

    if (intent != null) {

        Bundle bundle = intent.getBundleExtra("bundle");

        if (bundle != null) {
            String cmd = bundle.getString("command");

            int uid = bundle.getInt("uid", -1);

            int desiredUid = bundle.getInt("desiredUid", -1);

            if (uid != -1 && desiredUid != -1)
                up = SuDatabaseHelper.get(getContext(), uid, desiredUid, cmd);
        }// w  w  w.j a v a  2  s .c o  m
    }

    if (up != null) {

        String app = up.username;
        if (app == null || app.length() == 0)
            app = String.valueOf(up.uid);

        icon.setImageDrawable(Util.loadPackageIcon(getActivity(), up.packageName));

        title.setTextColor(((ActivityLog) getActivity()).textToolbar);
        subtitle.setTextColor(((ActivityLog) getActivity()).textToolbar);
        request.setTextColor(((ActivityLog) getActivity()).textToolbar);
        command.setTextColor(((ActivityLog) getActivity()).textToolbar);

        title.setText(up.getName());

        subtitle.setText(up.packageName + ", " + app);

        request.setText("Requested UID: " + up.desiredUid);

        command.setText(
                "Command: " + (TextUtils.isEmpty(up.command) ? getString(R.string.all_commands) : up.command));

        //getListView().setSelector(android.R.color.transparent);

    } else {
        callback = (LogCallback) getActivity();
    }

    LinearLayout logParent = (LinearLayout) getActivity().findViewById(R.id.log);
    LinearLayout notiParent = (LinearLayout) getActivity().findViewById(R.id.noti);

    int accent = ThemeStore.accentColor(getContext());

    TintHelper.setTint(log, accent, false);
    TintHelper.setTint(notification, accent, false);

    if (up == null) {
        log.setChecked(Settings.getLogging(getActivity()));

        notiParent.setVisibility(View.GONE);
        notification.setChecked(false);

    } else {
        log.setChecked(up.logging);

        notification.setChecked(up.notification);
    }

    logParent.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            log.setChecked(!log.isChecked());
        }
    });

    log.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (up == null) {
                Settings.setLogging(getActivity(), b);

            } else {
                up.logging = b;
                SuDatabaseHelper.setPolicy(getActivity(), up);
            }
        }
    });

    notiParent.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            notification.setChecked(!notification.isChecked());
        }
    });

    notification.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (up == null) {

            } else {
                up.notification = notification.isChecked();
                SuDatabaseHelper.setPolicy(getActivity(), up);
            }
        }
    });

    load();
    LocalBroadcastManager.getInstance(getContext()).registerReceiver(receiver,
            new IntentFilter(Common.INTENT_FILTER_LOG));
}

From source file:com.twofortyfouram.locale.sdk.host.ui.fragment.AbstractSupportPluginEditFragment.java

/**
 * Processes sub-activity results for plug-ins being edited {@inheritDoc}
 *///from   w  w  w.  j  av a 2  s. c  o  m
@Override
public final void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent intent) {

    if (REQUEST_CODE_EDIT_PLUGIN == requestCode) {
        switch (resultCode) {
        case Activity.RESULT_OK: {
            Lumberjack.always("Received result code RESULT_OK"); //$NON-NLS-1$

            final EnumSet<PluginErrorEdit> errors = PluginEditDelegate.isIntentValid(intent, mPlugin);
            if (errors.isEmpty()) {
                final Bundle newBundle = intent
                        .getBundleExtra(com.twofortyfouram.locale.api.Intent.EXTRA_BUNDLE);
                final String newBlurb = intent
                        .getStringExtra(com.twofortyfouram.locale.api.Intent.EXTRA_STRING_BLURB);

                Bundle previousBundle = null;
                String previousBlurb = null;
                if (null != mPreviousPluginInstanceData) {
                    try {
                        previousBundle = com.twofortyfouram.locale.sdk.host.internal.BundleSerializer
                                .deserializeFromByteArray(mPreviousPluginInstanceData.getSerializedBundle());
                    } catch (final ClassNotFoundException e) {
                        Lumberjack.e("Error deserializing previous bundle %s", //$NON-NLS-1$
                                e);
                    }
                    previousBlurb = mPreviousPluginInstanceData.getBlurb();
                }

                handleSaveInternal(newBundle, newBlurb, previousBundle, previousBlurb);
            } else {
                handleErrorsInternal(mPlugin, errors);
            }

            break;
        }
        case Activity.RESULT_CANCELED: {
            Lumberjack.always("Received result code RESULT_CANCELED"); //$NON-NLS-1$
            handleCancelInternal(mPlugin);
            break;
        }
        default: {
            Lumberjack.always("ERROR: Received illegal result code %d", //$NON-NLS-1$
                    resultCode);
            handleErrorsInternal(mPlugin, EnumSet.of(PluginErrorEdit.UNKNOWN_ACTIVITY_RESULT_CODE));
            /*
             * Although this shouldn't happen, don't throw an exception
             * because bad 3rd party apps could give bad result codes
             */

        }
        }
    } else {
        super.onActivityResult(requestCode, resultCode, intent);
    }
}

From source file:net.potterpcs.recipebook.RecipeBookActivity.java

private void handleIntent(Intent intent) {
    // Fill in all the search/sort criteria
    if (intent.hasExtra(RecipeBook.SEARCH_EXTRA)) {
        searchQuery = intent.getStringExtra(RecipeBook.SEARCH_EXTRA);
    } else {// w  ww.j  ava2  s .  c o  m
        searchQuery = intent.getStringExtra(SearchManager.QUERY);
    }

    searchMode = (searchQuery != null);

    Bundle searchData = intent.getBundleExtra(SearchManager.APP_DATA);
    if (searchData == null) {
        sortDescending = intent.getBooleanExtra(SORT_DESCENDING, false);
        sortKey = intent.getIntExtra(SORT_KEY, 0);
        tagSearchMode = intent.hasExtra(RecipeBook.TAG_EXTRA);
        searchTag = intent.getStringExtra(RecipeBook.TAG_EXTRA);
        searchMin = intent.getIntExtra(RecipeBook.TIME_EXTRA_MIN, 0);
        searchMax = intent.getIntExtra(RecipeBook.TIME_EXTRA_MAX, 0);
        timeSearchMode = (searchMin != 0 || searchMax != 0);
    } else {
        sortDescending = searchData.getBoolean(SORT_DESCENDING, false);
        sortKey = searchData.getInt(SORT_KEY, 0);
        tagSearchMode = searchData.containsKey(RecipeBook.TAG_EXTRA);
        searchTag = searchData.getString(RecipeBook.TAG_EXTRA);
        searchMin = searchData.getInt(RecipeBook.TIME_EXTRA_MIN, 0);
        searchMax = searchData.getInt(RecipeBook.TIME_EXTRA_MAX, 0);
        timeSearchMode = (searchMin != 0 || searchMax != 0);
    }

    // In case the max value is left blank
    if (searchMax == 0 && searchMin > 0) {
        searchMax = Integer.MAX_VALUE;
    }

    //      Log.i(TAG, "Sort descending == " + sortDescending + ", sort key == " + sortKey 
    //            + " max time == " + searchMax + " min time == " + searchMin);

    // Android 3.0+ has the action bar, and requires this call to change menu items.
    // Earlier versions don't have it, because they don't need it.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        invalidateOptionsMenu();
    }
}

From source file:fr.cobaltians.cobalt.activities.CobaltActivity.java

public void popTo(String controller, String page) {
    Intent popToIntent = Cobalt.getInstance(this).getIntentForController(controller, page);

    if (popToIntent != null) {
        Bundle popToExtras = popToIntent.getBundleExtra(Cobalt.kExtras);
        String popToActivityClassName = popToExtras.getString(Cobalt.kActivity);

        try {//from w w w . j a  v a2s . co  m
            Class<?> popToActivityClass = Class.forName(popToActivityClassName);

            boolean popToControllerFound = false;
            int popToControllerIndex = -1;

            for (int i = sActivitiesArrayList.size() - 1; i >= 0; i--) {
                Activity oldActivity = sActivitiesArrayList.get(i);
                Class<?> oldActivityClass = oldActivity.getClass();

                Bundle oldBundle = oldActivity.getIntent().getExtras();
                Bundle oldExtras = (oldBundle != null) ? oldBundle.getBundle(Cobalt.kExtras) : null;
                String oldPage = (oldExtras != null) ? oldExtras.getString(Cobalt.kPage) : null;

                if (oldPage == null && CobaltActivity.class.isAssignableFrom(oldActivityClass)) {
                    Fragment fragment = ((CobaltActivity) oldActivity).getSupportFragmentManager()
                            .findFragmentById(((CobaltActivity) oldActivity).getFragmentContainerId());
                    if (fragment != null) {
                        oldExtras = fragment.getArguments();
                        oldPage = (oldExtras != null) ? oldExtras.getString(Cobalt.kPage) : null;
                    }
                }

                if (popToActivityClass.equals(oldActivityClass) && (!CobaltActivity.class
                        .isAssignableFrom(oldActivityClass)
                        || (CobaltActivity.class.isAssignableFrom(oldActivityClass) && page.equals(oldPage)))) {
                    popToControllerFound = true;
                    popToControllerIndex = i;
                    break;
                }
            }

            if (popToControllerFound) {
                while (popToControllerIndex + 1 <= sActivitiesArrayList.size()) {
                    sActivitiesArrayList.get(popToControllerIndex + 1).finish();
                }
            } else if (Cobalt.DEBUG)
                Log.w(Cobalt.TAG, TAG + " - popTo: controller " + controller
                        + (page == null ? "" : " with page " + page) + " not found in history. Abort.");
        } catch (ClassNotFoundException exception) {
            exception.printStackTrace();
        }
    } else if (Cobalt.DEBUG)
        Log.e(Cobalt.TAG, TAG + " - popTo: unable to pop to null controller");
}

From source file:org.tvheadend.tvhclient.SearchResultActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Quit if the search mode is not active
    if (!Intent.ACTION_SEARCH.equals(intent.getAction()) || !intent.hasExtra(SearchManager.QUERY)) {
        return;//from w w  w.  ja  v  a  2s .c o m
    }

    // Get the possible channel
    TVHClientApplication app = (TVHClientApplication) getApplication();
    Bundle bundle = intent.getBundleExtra(SearchManager.APP_DATA);
    if (bundle != null) {
        channel = app.getChannel(bundle.getLong(Constants.BUNDLE_CHANNEL_ID));
    } else {
        channel = null;
    }

    // Create the intent with the search options 
    String query = intent.getStringExtra(SearchManager.QUERY);
    pattern = Pattern.compile(query, Pattern.CASE_INSENSITIVE);
    intent = new Intent(SearchResultActivity.this, HTSService.class);
    intent.setAction(Constants.ACTION_EPG_QUERY);
    intent.putExtra("query", query);
    if (channel != null) {
        intent.putExtra(Constants.BUNDLE_CHANNEL_ID, channel.id);
    }

    // Save the query so it can be shown again
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SuggestionProvider.AUTHORITY,
            SuggestionProvider.MODE);
    suggestions.saveRecentQuery(query, null);

    // Now call the service with the query to get results
    startService(intent);

    // Clear the previous results before adding new ones
    adapter.clear();

    // If no channel is given go through the list of programs in all
    // channels and search if the desired program exists. If a channel was
    // given search through the list of programs in the given channel. 
    if (channel == null) {
        for (Channel ch : app.getChannels()) {
            if (ch != null) {
                synchronized (ch.epg) {
                    for (Program p : ch.epg) {
                        if (p != null && p.title != null && p.title.length() > 0) {
                            // Check if the program name matches the search pattern
                            if (pattern.matcher(p.title).find()) {
                                adapter.add(p);
                                adapter.sort();
                                adapter.notifyDataSetChanged();
                            }
                        }
                    }
                }
            }
        }
    } else {
        if (channel.epg != null) {
            synchronized (channel.epg) {
                for (Program p : channel.epg) {
                    if (p != null && p.title != null && p.title.length() > 0) {
                        // Check if the program name matches the search pattern
                        if (pattern.matcher(p.title).find()) {
                            adapter.add(p);
                            adapter.sort();
                            adapter.notifyDataSetChanged();
                        }
                    }
                }
            }
        }
    }

    actionBar.setTitle(android.R.string.search_go);
    actionBar.setSubtitle(getString(R.string.loading));

    // Create the runnable that will initiate the update of the adapter and
    // indicates that we are done when nothing has happened after 2s. 
    updateTask = new Runnable() {
        public void run() {
            adapter.notifyDataSetChanged();
            actionBar.setSubtitle(adapter.getCount() + " " + getString(R.string.results));
        }
    };
}