Example usage for android.content Intent ACTION_GET_CONTENT

List of usage examples for android.content Intent ACTION_GET_CONTENT

Introduction

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

Prototype

String ACTION_GET_CONTENT

To view the source code for android.content Intent ACTION_GET_CONTENT.

Click Source Link

Document

Activity Action: Allow the user to select a particular kind of data and return it.

Usage

From source file:com.davidmascharka.lips.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.
    switch (item.getItemId()) {
    case R.id.action_reset:
        resetDatafile();/*from  w  ww.  jav  a 2s.  c o m*/
        break;
    case R.id.action_select_building:
        showSelectBuildingDialog();
        break;
    case R.id.action_select_room_size:
        new SelectRoomSizeDialogFragment().show(getSupportFragmentManager(), "RoomSize");
        break;
    case R.id.action_display_map:
        displayMap = !displayMap;
        item.setChecked(displayMap);
        ((GridView) findViewById(R.id.gridView)).setDisplayMap(displayMap);
        break;
    case R.id.action_select_map:
        // Launch an intent to select the map the user wants to display
        Intent selectMapIntent = new Intent();
        selectMapIntent.setAction(Intent.ACTION_GET_CONTENT);
        selectMapIntent.setType("image/*");
        selectMapIntent.addCategory(Intent.CATEGORY_OPENABLE);

        if (selectMapIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(selectMapIntent, GET_MAP_REQUEST);
        }
        break;
    case R.id.action_start_tracker:
        Intent intent = new Intent(this, TrackerActivity.class);
        startActivity(intent);
        break;
    default:
        super.onOptionsItemSelected(item);
        break;
    }
    return true;
}

From source file:com.klinker.android.twitter.activities.profile_viewer.ProfilePager.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case android.R.id.home:
        onBackPressed();/*from   ww  w  .  j a va  2 s .  com*/
        return true;

    case R.id.menu_follow:
        new FollowUser().execute();
        return true;

    case R.id.menu_unfollow:
        new FollowUser().execute();
        return true;

    case R.id.menu_favorite:
        new FavoriteUser().execute();
        return true;

    case R.id.menu_unfavorite:
        new FavoriteUser().execute();
        return true;

    case R.id.menu_block:
        new BlockUser().execute();
        sharedPrefs.edit().putBoolean("just_muted", true).commit();
        return true;

    case R.id.menu_unblock:
        new BlockUser().execute();
        return true;

    case R.id.menu_add_to_list:
        new GetLists().execute();
        return true;

    case R.id.menu_tweet:
        Intent compose = new Intent(context, ComposeActivity.class);
        compose.putExtra("user", "@" + screenName);
        startActivity(compose);
        return true;

    case R.id.menu_dm:
        Intent dm = new Intent(context, ComposeDMActivity.class);
        dm.putExtra("screenname", screenName);
        startActivity(dm);
        return true;

    case R.id.menu_change_picture:
        Intent photoPickerIntent = new Intent();
        photoPickerIntent.setType("image/*");
        photoPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
        try {
            startActivityForResult(Intent.createChooser(photoPickerIntent, "Select Picture"), SELECT_PRO_PIC);
        } catch (Throwable t) {
            // no app to preform this..? hmm, tell them that I guess
            Toast.makeText(context, "No app available to select pictures!", Toast.LENGTH_SHORT).show();
        }
        return true;

    case R.id.menu_change_banner:
        Intent bannerPickerIntent = new Intent();
        bannerPickerIntent.setType("image/*");
        bannerPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
        try {
            startActivityForResult(Intent.createChooser(bannerPickerIntent, "Select Picture"), SELECT_BANNER);
        } catch (Throwable t) {
            // no app to preform this..? hmm, tell them that I guess
            Toast.makeText(context, "No app available to select pictures!", Toast.LENGTH_SHORT).show();
        }
        return true;

    case R.id.menu_change_bio:
        updateProfile();
        return true;

    case R.id.menu_mute:
        String current = sharedPrefs.getString("muted_users", "");
        sharedPrefs.edit()
                .putString("muted_users", current + screenName.replaceAll(" ", "").replaceAll("@", "") + " ")
                .commit();
        sharedPrefs.edit().putBoolean("refresh_me", true).commit();
        sharedPrefs.edit().putBoolean("just_muted", true).commit();
        finish();
        return true;

    case R.id.menu_unmute:
        String muted = sharedPrefs.getString("muted_users", "");
        muted = muted.replace(screenName + " ", "");
        sharedPrefs.edit().putString("muted_users", muted).commit();
        sharedPrefs.edit().putBoolean("refresh_me", true).commit();
        sharedPrefs.edit().putBoolean("just_muted", true).commit();
        finish();
        return true;

    case R.id.menu_mute_rt:
        String muted_rts = sharedPrefs.getString("muted_rts", "");
        sharedPrefs.edit()
                .putString("muted_rts", muted_rts + screenName.replaceAll(" ", "").replaceAll("@", "") + " ")
                .commit();
        sharedPrefs.edit().putBoolean("refresh_me", true).commit();
        sharedPrefs.edit().putBoolean("just_muted", true).commit();
        finish();
        return true;

    case R.id.menu_unmute_rt:
        String curr_muted = sharedPrefs.getString("muted_rts", "");
        curr_muted = curr_muted.replace(screenName + " ", "");
        sharedPrefs.edit().putString("muted_rts", curr_muted).commit();
        sharedPrefs.edit().putBoolean("refresh_me", true).commit();
        sharedPrefs.edit().putBoolean("just_muted", true).commit();
        finish();
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.sim2dial.dialer.ChatFragment.java

private void pickImage() {
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name));
    imageToUploadUri = Uri.fromFile(file);
    captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageToUploadUri);
    cameraIntents.add(captureIntent);/*from www .  ja  v  a2s.  c o  m*/

    final Intent galleryIntent = new Intent();
    galleryIntent.setType("image/*");
    galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

    final Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.image_picker_title));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));

    startActivityForResult(chooserIntent, ADD_PHOTO);
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

/**
 * Called when the activity is first created.
 *///from  w  ww. j  a va2  s. c o m
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (debug) {
        Log.d(TAG, "Shopping list onCreate()");
    }

    mSortOrder = PreferenceActivity.getShoppingListSortOrderFromPrefs(this);

    mDistribution.setFirst(MENU_DISTRIBUTION_START, DIALOG_DISTRIBUTION_START);

    // Check whether EULA has been accepted
    // or information about new version can be presented.
    if (false && mDistribution.showEulaOrNewVersion()) {
        return;
    }

    setContentView(R.layout.activity_shopping);

    // mEditItemPosition = -1;

    // Automatic requeries (once a second)
    mUpdateInterval = 2000;
    mUpdating = false;

    // General Uris:
    mListUri = ShoppingContract.Lists.CONTENT_URI;
    mItemUri = ShoppingContract.Items.CONTENT_URI;
    mListItemUri = ShoppingContract.Items.CONTENT_URI;

    int defaultShoppingList = getLastUsedListFromPrefs();

    // Handle the calling intent
    final Intent intent = getIntent();
    final String type = intent.resolveType(this);
    final String action = intent.getAction();

    if (action == null) {
        // Main action
        mState = STATE_MAIN;

        mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);

        intent.setData(mListUri);
    } else if (Intent.ACTION_MAIN.equals(action)) {
        // Main action
        mState = STATE_MAIN;

        mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);

        intent.setData(mListUri);

    } else if (Intent.ACTION_VIEW.equals(action)) {
        mState = STATE_VIEW_LIST;

        setListUriFromIntent(intent.getData(), type);
    } else if (Intent.ACTION_INSERT.equals(action)) {

        mState = STATE_VIEW_LIST;

        setListUriFromIntent(intent.getData(), type);

    } else if (Intent.ACTION_PICK.equals(action)) {
        mState = STATE_PICK_ITEM;

        mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);
    } else if (Intent.ACTION_GET_CONTENT.equals(action)) {
        mState = STATE_GET_CONTENT_ITEM;

        mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);
    } else if (GeneralIntents.ACTION_INSERT_FROM_EXTRAS.equals(action)) {
        if (ShoppingListIntents.TYPE_STRING_ARRAYLIST_SHOPPING.equals(type)) {
            /*
             * Need to insert new items from a string array in the intent
            * extras Use main action but add an item to the options menu
            * for adding extra items
            */
            getShoppingExtras(intent);
            mState = STATE_MAIN;
            mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + defaultShoppingList);
            intent.setData(mListUri);
        } else if (intent.getDataString().startsWith(ShoppingContract.Lists.CONTENT_URI.toString())) {
            // Somewhat quick fix to pass data from ShoppingListsActivity to
            // this activity.

            // We received a valid shopping list URI:
            mListUri = intent.getData();

            getShoppingExtras(intent);
            mState = STATE_MAIN;
            intent.setData(mListUri);
        }
    } else {
        // Unknown action.
        Log.e(TAG, "Shopping: Unknown action, exiting");
        finish();
        return;
    }

    // hook up all buttons, lists, edit text:
    createView();

    // populate the lists
    fillListFilter();

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    // Get last part of URI:
    int selectList;
    try {
        selectList = Integer.parseInt(mListUri.getLastPathSegment());
    } catch (NumberFormatException e) {
        selectList = defaultShoppingList;
    }

    // select the default shopping list at the beginning:
    setSelectedListId(selectList);

    if (icicle != null) {
        String prevText = icicle.getString(ORIGINAL_ITEM);
        if (prevText != null) {
            mEditText.setTextKeepState(prevText);
        }
        // mTextEntryMenu = icicle.getInt(BUNDLE_TEXT_ENTRY_MENU);
        // mEditItemPosition = icicle.getInt(BUNDLE_CURSOR_ITEMS_POSITION);
        mItemUri = Uri.parse(icicle.getString(BUNDLE_ITEM_URI));
        List<String> pathSegs = mItemUri.getPathSegments();
        int num = pathSegs.size();
        mListItemUri = Uri.withAppendedPath(mListUri, pathSegs.get(num - 1));
        if (icicle.containsKey(BUNDLE_RELATION_URI)) {
            mRelationUri = Uri.parse(icicle.getString(BUNDLE_RELATION_URI));
        }
        mItemsView.mMode = icicle.getInt(BUNDLE_MODE);
        mItemsView.mModeBeforeSearch = icicle.getInt(BUNDLE_MODE_BEFORE_SEARCH);
    }

    // set focus to the edit line:
    mEditText.requestFocus();

    // TODO remove initFromPreferences from onCreate
    // we need it in resume to update after settings have changed
    initFromPreferences();
    // now update title and fill all items
    onModeChanged();

    mItemsView.setActionBarListener(this);
    mItemsView.setUndoListener(this);

    if ("myo".equals(BuildConfig.FLAVOR)) {
        try {
            Class myoToggleBoughtInputMethod = Class
                    .forName("org.openintents.shopping.ui.MyoToggleBoughtInputMethod");
            Constructor constructor = myoToggleBoughtInputMethod
                    .getConstructor(new Class[] { ShoppingActivity.class, mItemsView.getClass() });
            toggleBoughtInputMethod = (ToggleBoughtInputMethod) constructor
                    .newInstance(new Object[] { this, mItemsView });
        } catch (ClassNotFoundException e) {
        } catch (NoSuchMethodException e) {
        } catch (InvocationTargetException e) {
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
        }
    }
}

From source file:com.dvn.vindecoder.ui.seller.AddVehicalAndPayment.java

private void startDilog() {
    AlertDialog.Builder myAlertDilog = new AlertDialog.Builder(AddVehicalAndPayment.this);
    myAlertDilog.setTitle("Upload picture option..");
    myAlertDilog.setMessage("Take Photo");
    myAlertDilog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
        @Override/*from  w w w  .j av  a  2  s  .  com*/
        public void onClick(DialogInterface dialog, int which) {
            Intent picIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
            picIntent.setType("image/*");
            picIntent.putExtra("return_data", true);
            startActivityForResult(picIntent, GALLERY_REQUEST);
        }
    });
    myAlertDilog.setNegativeButton("Camera", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (checkPermission(Manifest.permission.CAMERA, AddVehicalAndPayment.this)) {
                    openCameraApplication();
                } else {
                    requestPermission(AddVehicalAndPayment.this, new String[] { Manifest.permission.CAMERA },
                            REQUEST_ACESS_CAMERA);
                }
            } else {
                openCameraApplication();
            }
        }
    });
    myAlertDilog.show();
}

From source file:com.buddi.client.dfu.DfuActivity.java

private void openFileChooser() {
    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType(mFileTypeTmp == DfuService.TYPE_AUTO ? DfuService.MIME_TYPE_ZIP : DfuService.MIME_TYPE_HEX);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        // file browser has been found on the device
        startActivityForResult(intent, SELECT_FILE_REQ);
    } else {/*from   w w  w.java 2s  .c  o m*/
        // there is no any file browser app, let's try to download one
        final View customView = getLayoutInflater().inflate(R.layout.app_file_browser, null);
        final ListView appsList = (ListView) customView.findViewById(android.R.id.list);
        appsList.setAdapter(new FileBrowserAppsAdapter(this));
        appsList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        appsList.setItemChecked(0, true);
        new AlertDialog.Builder(this).setTitle(R.string.dfu_alert_no_filebrowser_title).setView(customView)
                .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        dialog.dismiss();
                    }
                }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        final int pos = appsList.getCheckedItemPosition();
                        if (pos >= 0) {
                            final String query = getResources()
                                    .getStringArray(R.array.dfu_app_file_browser_action)[pos];
                            final Intent storeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(query));
                            startActivity(storeIntent);
                        }
                    }
                }).show();
    }
}

From source file:org.catrobat.catroid.ui.fragment.SoundFragment.java

public void addSoundChooseFile() {
    isAddNewSoundButtonClicked = true;//from  w  ww.  ja v a  2s  . c o m
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("audio/*");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        disableGoogleDrive(intent);
    }
    startActivityForResult(Intent.createChooser(intent, getString(R.string.sound_select_source)),
            SoundController.REQUEST_SELECT_MUSIC);
}

From source file:com.safecell.HomeScreenActivity.java

private void dialogMessage() {
    Dialog dialog = new AlertDialog.Builder(HomeScreenActivity.this).setMessage("Select Profile Picture")
            .setPositiveButton("Photo Library", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    Intent intent = new Intent();
                    intent.setType("image/*");
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    startActivityForResult(intent, 1);

                }/*from ww w  .  j a  v  a 2 s. c om*/
            }).setNegativeButton("New Photo", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(cameraIntent, 2);

                    /*
                     * Intent nintent = new Intent(
                     * MediaStore.ACTION_IMAGE_CAPTURE);
                     * captureimage_filename = String
                     * .valueOf(System.currentTimeMillis()) +
                     * ".jpg";
                     * 
                     * File file = new File(Environment
                     * .getExternalStorageDirectory(),
                     * captureimage_filename );
                     * captureimage_filename_absolutepath =
                     * file.getAbsolutePath(); outputFileUri =
                     * Uri.fromFile(file);
                     * nintent.putExtra(MediaStore.EXTRA_OUTPUT,
                     * outputFileUri);
                     * startActivityForResult(nintent, 2);
                     */
                }
            }).create();
    dialog.show();
}

From source file:org.safegees.safegees.gui.view.PrincipalMapActivity.java

public void pickImage(View View) {
    //pickImage(v);
    Log.i("Picked image", "true");
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, REQUEST_IMAGE_CODE);
}

From source file:com.xxjwd.chat.ChatActivity.java

 /**
 * /*w w w .ja  v a2 s .com*/
 */
private void selectFileFromLocal() {
   Intent intent = null;
   if (Build.VERSION.SDK_INT < 19) {
      intent = new Intent(Intent.ACTION_GET_CONTENT);
      intent.setType("*/*");
      intent.addCategory(Intent.CATEGORY_OPENABLE);

   } else {
      intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
   }
   startActivityForResult(intent, REQUEST_CODE_SELECT_FILE);
}