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.mk4droid.IMC_Activities.Fragment_NewIssueA.java

/**
 *          OnCreateView /* w w  w  . ja  v  a 2 s.co  m*/
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    flagStarter = true;

    FActivity_TabHost.IndexGroup = 2;
    vfrag_nIssueA = inflater.inflate(R.layout.fragment_newissue_a, container, false);

    mfrag_nIssueA = this;

    ctx = this.getActivity();

    //-------- tvUnauth ---- 
    llUnauth = (LinearLayout) vfrag_nIssueA.findViewById(R.id.llUnauth);

    Button gotoSetup = (Button) llUnauth.findViewById(R.id.bt_nia_gosetup);
    gotoSetup.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().finish();

            // Check if Activity Splash Already open
            if (Activity_Splash_Login.et_username == null) {
                Log.e("NIA", "SPLASH WAS NULL");
                startActivity(new Intent(ctx, Activity_Splash_Login.class));
            }

            getActivity().finish();
        }
    });

    //---- Spinner -----
    ArrayList<Category> mCatL_Sorted = SortCategList(Service_Data.mCategL);
    SpinnerArrString = initSpinner(mCatL_Sorted);

    sp = (Spinner) vfrag_nIssueA.findViewById(R.id.spinnerCateg);

    adapterSP = new SpinnerAdapter_NewIssueCateg(getActivity(), //--- Set spinner adapter --
            android.R.layout.simple_spinner_item, mCatL_Sorted);
    sp.setAdapter(adapterSP);

    sp.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View arg1, int arg2, long arg3) {

            if (flagStarter) {
                flagStarter = false;
            } else {
                spPosition = arg2;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    //--------- Title -----

    et_title = (EditText) vfrag_nIssueA.findViewById(R.id.etTitle_ni);

    if (et_title != null)
        if (et_title.getText().toString().length() > 0)
            titleData_STR = et_title.getText().toString();

    if (titleData_STR.length() > 0)
        et_title.setText(titleData_STR);

    //------ Description ----

    et_descr = (EditText) vfrag_nIssueA.findViewById(R.id.etDescription);
    if (et_descr != null)
        if (et_descr.getText().toString().length() > 0)
            descriptionData_STR = et_descr.getText().toString();

    //------- Bt Attach image ---
    btAttachImage = (ImageButton) vfrag_nIssueA.findViewById(R.id.btAttach_image);

    //-------- Bt Proceed -----
    btProceed = (Button) vfrag_nIssueA.findViewById(R.id.btProceed_ni_B);

    mshPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    resources = SetResources();

    //--------- Layout -------
    llnewissue_a = (LinearLayout) vfrag_nIssueA.findViewById(R.id.llnewissue_a);
    llnewissue_a.setVisibility(View.VISIBLE);

    //-------- Take Image button -------
    if (flagPictureTaken && Image_BMP != null) {

        btAttachImage.setScaleType(ScaleType.CENTER_CROP);

        try {
            btAttachImage.setImageBitmap(Image_BMP);
        } catch (Exception e) {

            // if the btAttachImage was null set Image with some delay
            btAttachImage.postDelayed(new Runnable() {
                @Override
                public void run() {
                    btAttachImage.setImageBitmap(Image_BMP);
                }
            }, 1000);
        }
        ;
    } else {
        btAttachImage.setScaleType(ScaleType.CENTER_INSIDE);
        btAttachImage.setImageResource(R.drawable.bt_custom_camera_round); //R.drawable.pattern_camera_repeater));
    }

    btAttachImage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

            builder.setTitle(FActivity_TabHost.resources.getString(R.string.Attachanimage));
            builder.setIcon(android.R.drawable.ic_menu_gallery);

            // 1 select
            builder.setPositiveButton(FActivity_TabHost.resources.getString(R.string.Gallery),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                            dialog.dismiss();

                            Intent intent = new Intent();
                            intent.setType("image/jpeg");
                            intent.setAction(Intent.ACTION_GET_CONTENT);
                            startActivityForResult(Intent.createChooser(intent, "Select Picture"),
                                    SELECT_PICTURE);
                        }
                    });

            // 2 Shoot
            builder.setNeutralButton(FActivity_TabHost.resources.getString(R.string.Camera),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                            dialog.dismiss();
                            // 2 shoot 
                            fimg = new File(image_path_source_temp);
                            Uri uri = Uri.fromFile(fimg);

                            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

                            startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
                        }
                    });

            // 3 clear 
            builder.setNegativeButton(FActivity_TabHost.resources.getString(R.string.Clear),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            //dialog.cancel();

                            flagPictureTaken = false;
                            File imagef = new File(image_path_source_temp);
                            imagef.delete();

                            dialog.dismiss();

                            //btAttachImage.setCompoundDrawablesWithIntrinsicBounds( 0, R.drawable.bt_custom_camera_round, 0,  0);
                            btAttachImage.setScaleType(ScaleType.CENTER_INSIDE);
                            btAttachImage.setImageResource(R.drawable.bt_custom_camera_round);

                            //   btAttachImage.setPadding(0, 40, 0, 0);
                        }
                    });

            builder.create();
            builder.show();
        }
    });

    //------------- button Proceed ----------
    btProceed.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View vBt) {

            // Check if title is long enough and sent
            if (et_title.getText().toString().length() > 2 && spPosition != -1
                    && et_descr.getText().toString().length() > 2) { // RRR

                titleData_STR = et_title.getText().toString();

                if (et_descr.getText().toString().length() > 0)
                    descriptionData_STR = et_descr.getText().toString();

                // Close Keyboard
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Service.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(et_title.getWindowToken(), 0);
                imm.hideSoftInputFromWindow(et_descr.getWindowToken(), 0);

                // Instantiate a new fragment.
                mfrag_nIssueB = new Fragment_NewIssueB();

                Bundle args = new Bundle();
                args.putInt("IndexSpinner", sp.getSelectedItemPosition());
                mfrag_nIssueB.setArguments(args);

                // Add the fragment to the activity, pushing this transaction
                // on to the back stack.
                FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                ft.add(mfrag_nIssueA.getId(), mfrag_nIssueB, "FTAG_NEW_ISSUE_B");
                ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                ft.addToBackStack(null);
                ft.commit();
            } else if (spPosition == -1) {
                Toast.makeText(getActivity(), resources.getString(R.string.SelectaCategory), tlv).show();
            } else if (et_title.getText().toString().length() <= 2) {
                Toast.makeText(getActivity(), resources.getString(R.string.LongerTitle), tlv).show();
            } else if (et_descr.getText().toString().length() <= 2) {
                Toast.makeText(getActivity(), resources.getString(R.string.LongerDescription), tlv).show();
            }
        }
    });

    return vfrag_nIssueA;
}

From source file:com.zira.registration.DocumentUploadActivity.java

protected void selectImage() {

    final CharSequence[] options = { "Take Photo", "Choose from Gallery", "Cancel" };

    AlertDialog.Builder builder = new AlertDialog.Builder(DocumentUploadActivity.this);
    builder.setTitle("Add Photo!");
    builder.setItems(options, new DialogInterface.OnClickListener() {
        @Override//  w w w . j a  v  a2s . co  m
        public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals("Take Photo")) {
                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                // Ensure that there's a camera activity to handle the intent
                if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                    // Create the File where the photo should go
                    File photoFile = null;
                    try {
                        mCurrentPhotoPath = Util.createImageFile();
                        photoFile = new File(mCurrentPhotoPath);
                    } catch (Exception ex) {
                        // Error occurred while creating the File
                        ex.printStackTrace();
                    }
                    // Continue only if the File was successfully created
                    if (photoFile != null) {
                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                        startActivityForResult(takePictureIntent, 1);
                    }
                }
            } else if (options[item].equals("Choose from Gallery")) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, "Select Picture"), 2);
            } else if (options[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }
    });
    builder.show();

}

From source file:com.freeme.filemanager.view.FileViewFragment.java

public void init() {
    long time1 = System.currentTimeMillis();
    //Debug.startMethodTracing("file_view");
    ViewStub stub = (ViewStub) mRootView.findViewById(R.id.viewContaniner);
    stub.setLayoutResource(R.layout.file_explorer_list);
    stub.inflate();/*from  w w w. ja v a 2 s.c  o  m*/
    ActivitiesManager.getInstance().registerActivity(ActivitiesManager.ACTIVITY_FILE_VIEW, mActivity);

    mFileCagetoryHelper = new FileCategoryHelper(mActivity);
    mFileViewInteractionHub = new FileViewInteractionHub(this, 1);
    // */ modify by droi liuhaoran for stop run
    /*/ Added by tyd wulianghuan 2013-12-12
    mCleanUpDatabaseHelper = new CleanUpDatabaseHelper(mActivity);
    mDatabase = mCleanUpDatabaseHelper.openDatabase();
    mFolderNameMap = new HashMap<String, String>();
    //*/

    // */add by droi liuhaoran for get Sd listener on 20160419
    mApplication = (FileManagerApplication) mActivity.getApplication();
    // */

    // notifyFileChanged();
    Intent intent = mActivity.getIntent();
    String action = intent.getAction();
    if (!TextUtils.isEmpty(action)
            && (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT))) {
        mFileViewInteractionHub.setMode(Mode.Pick);

        boolean pickFolder = intent.getBooleanExtra(PICK_FOLDER, false);
        if (!pickFolder) {
            String[] exts = intent.getStringArrayExtra(EXT_FILTER_KEY);
            if (exts != null) {
                mFileCagetoryHelper.setCustomCategory(exts);
            }
        } else {
            mFileCagetoryHelper.setCustomCategory(new String[] {} /*
                                                                  * folder
                                                                  * only
                                                                  */);
            mRootView.findViewById(R.id.pick_operation_bar).setVisibility(View.VISIBLE);

            mRootView.findViewById(R.id.button_pick_confirm).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    try {
                        Intent intent = Intent.parseUri(mFileViewInteractionHub.getCurrentPath(), 0);
                        mActivity.setResult(Activity.RESULT_OK, intent);
                        mActivity.finish();
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                }
            });

            mRootView.findViewById(R.id.button_pick_cancel).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mActivity.finish();
                }
            });
        }
    } else {
        mFileViewInteractionHub.setMode(Mode.View);
    }
    mVolumeSwitch = (ImageButton) mRootView.findViewById(R.id.volume_navigator);
    updateVolumeSwitchState();
    mGalleryNavigationBar = (RelativeLayout) mRootView.findViewById(R.id.gallery_navigation_bar);
    mVolumeSwitch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            int visibility = getVolumesListVisibility();
            if (visibility == View.GONE) {
                buildVolumesList();
                showVolumesList(true);
            } else if (visibility == View.VISIBLE) {
                showVolumesList(false);
            }
        }

    });
    mFileListView = (ListView) mRootView.findViewById(R.id.file_path_list);
    mFileIconHelper = new FileIconHelper(mActivity);
    mAdapter = new FileListAdapter(mActivity, R.layout.file_browser_item, mFileNameList,
            mFileViewInteractionHub, mFileIconHelper);

    boolean baseSd = intent.getBooleanExtra(GlobalConsts.KEY_BASE_SD,
            !FileExplorerPreferenceActivity.isReadRoot(mActivity));
    Log.i(LOG_TAG, "baseSd = " + baseSd);

    String rootDir = intent.getStringExtra(ROOT_DIRECTORY);
    if (!TextUtils.isEmpty(rootDir)) {
        if (baseSd && this.sdDir.startsWith(rootDir)) {
            rootDir = this.sdDir;
        }
    } else {
        rootDir = baseSd ? this.sdDir : GlobalConsts.ROOT_PATH;
    }

    String currentDir = FileExplorerPreferenceActivity.getPrimaryFolder(mActivity);
    Uri uri = intent.getData();
    if (uri != null) {
        if (baseSd && this.sdDir.startsWith(uri.getPath())) {
            currentDir = this.sdDir;
        } else {
            currentDir = uri.getPath();
        }
    }
    initVolumeState();
    mBackspaceExit = (uri != null) && (TextUtils.isEmpty(action)
            || (!action.equals(Intent.ACTION_PICK) && !action.equals(Intent.ACTION_GET_CONTENT)));

    mFileListView.setAdapter(mAdapter);
    IntentFilter intentFilter = new IntentFilter();
    // add by xueweili for get sdcard
    intentFilter.setPriority(1000);

    /*
     * intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
     * intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
     * intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
     * intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
     * intentFilter.addAction(Intent.ACTION_MEDIA_EJECT);
     */
    if (!mReceiverTag) {
        mReceiverTag = true;
        intentFilter.addAction(GlobalConsts.BROADCAST_REFRESH);
        intentFilter.addDataScheme("file");
        mActivity.registerReceiver(mReceiver, intentFilter);
    }

    // */add by droi liuhaoran for get Sd listener on 20160419
    mApplication.addSDCardChangeListener(this);
    // */

    setHasOptionsMenu(true);

    // add by mingjun for load file
    mRootView.addOnLayoutChangeListener(new OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6,
                int arg7, int arg8) {
            isLayout = arg1;
        }
    });
    loadDialog = new ProgressDialog(mRootView.getContext());
}

From source file:de.kodejak.hashr.fragmentHashFromFile.java

public void OnButtonChooseFileClick() {
    Intent chooseFile;//  w  ww  .  ja v a  2 s .  com
    Intent intent;
    chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
    chooseFile.setType("file/*");
    intent = Intent.createChooser(chooseFile, "Choose a file");
    fileJob = 0; // open to generate
    getActivity().startActivityForResult(intent, ACTIVITY_CHOOSE_FILE);
}

From source file:net.inbox.InboxSend.java

private void dialog_attachments() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.send_attachments));
    populate_list_view();// w ww.  j a  va 2s . c o  m
    builder.setView(attachments_list);
    builder.setCancelable(true);
    builder.setPositiveButton(getString(R.string.attch_add_attachment), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("file:///*");
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            try {
                startActivityForResult(Intent.createChooser(intent, "Pick Attachment"), 0);
            } catch (android.content.ActivityNotFoundException e) {
                dialog_no_fm();
            }
        }
    });

    attachments_dialog = builder.show();

    if (!warned_8_bit_absent && !current_inbox.get_smtp_extensions().equals("-1")
            && !current_inbox.smtp_check_extension("8BITMIME")) {
        warned_8_bit_absent = true;
        Dialogs.dialog_error_line(getString(R.string.err_no_8_bit_mime), this);
    }
}

From source file:com.android.documentsui.DocumentsActivity.java

private void buildDefaultState() {
    mState = new State();

    final Intent intent = getIntent();
    final String action = intent.getAction();
    if (Intent.ACTION_OPEN_DOCUMENT.equals(action)) {
        mState.action = ACTION_OPEN;//ww w .  ja va 2s .  co m
    } else if (Intent.ACTION_CREATE_DOCUMENT.equals(action)) {
        mState.action = ACTION_CREATE;
    } else if (Intent.ACTION_GET_CONTENT.equals(action)) {
        mState.action = ACTION_GET_CONTENT;
    } else if (DocumentsContract.ACTION_MANAGE_ROOT.equals(action)) {
        mState.action = ACTION_MANAGE;
    }

    if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
        mState.allowMultiple = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
    }

    if (mState.action == ACTION_MANAGE) {
        mState.acceptMimes = new String[] { "*/*" };
        mState.allowMultiple = true;
    } else if (intent.hasExtra(Intent.EXTRA_MIME_TYPES)) {
        mState.acceptMimes = intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES);
    } else {
        mState.acceptMimes = new String[] { intent.getType() };
    }

    mState.localOnly = intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false);
    mState.forceAdvanced = intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false);
    mState.showAdvanced = mState.forceAdvanced | SettingsActivity.getDisplayAdvancedDevices(this);
}

From source file:com.nextgis.mobile.MainActivity.java

protected void onAdd(int nType) {
    switch (nType) {
    case DS_TYPE_ZIP:
        Intent intent_zip = new Intent(Intent.ACTION_GET_CONTENT);
        intent_zip.setType("application/zip");
        intent_zip.addCategory(Intent.CATEGORY_OPENABLE);

        try {/*w  ww. ja  v a2 s  . c  om*/
            startActivityForResult(Intent.createChooser(intent_zip, getString(R.string.message_select_file)),
                    DS_TYPE_ZIP);
        } catch (ActivityNotFoundException e) {
            // Potentially direct the user to the Market with a Dialog
            Toast.makeText(this, R.string.error_file_manager, Toast.LENGTH_SHORT).show();
        }

        break;
    case DS_TYPE_TMS:
        mMap.createLayer(null, nType);
        break;
    case DS_TYPE_LOCAL_GEOJSON:
        Intent intent_geojson = new Intent(Intent.ACTION_GET_CONTENT);
        intent_geojson.setType("application/json");
        intent_geojson.addCategory(Intent.CATEGORY_OPENABLE);

        try {
            startActivityForResult(
                    Intent.createChooser(intent_geojson, getString(R.string.message_select_file)),
                    DS_TYPE_LOCAL_GEOJSON);
        } catch (ActivityNotFoundException e) {
            // Potentially direct the user to the Market with a Dialog
            Toast.makeText(this, R.string.error_file_manager, Toast.LENGTH_SHORT).show();
        }
        break;
    }
}

From source file:info.shibafu528.gallerymultipicker.MultiPickerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);
    int id = item.getItemId();
    if (id == android.R.id.home) {
        if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
            getSupportFragmentManager().popBackStack();
        } else {//from ww w .  j a  v a  2  s  .  c o  m
            setResult(RESULT_CANCELED);
            finish();
        }
    } else if (id == R.id.info_shibafu528_gallerymultipicker_action_decide) {
        accept(getSelectedUris());
    } else if (id == R.id.info_shibafu528_gallerymultipicker_action_gallery) {
        Intent intent = new Intent(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? Intent.ACTION_PICK
                : Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
        startActivityForResult(intent, REQUEST_GALLERY);
    } else if (id == R.id.info_shibafu528_gallerymultipicker_action_take_a_photo) {
        boolean existExternal = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
        if (!existExternal) {
            Toast.makeText(this, R.string.info_shibafu528_gallerymultipicker_storage_error, Toast.LENGTH_SHORT)
                    .show();
            return true;
        } else {
            File extDestDir = new File(
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
                    mCameraDestDir != null ? mCameraDestDir : "Camera");
            if (!extDestDir.exists()) {
                extDestDir.mkdirs();
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
            String fileName = sdf.format(new Date(System.currentTimeMillis()));
            File destFile = new File(extDestDir.getPath(), fileName + ".jpg");
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.TITLE, fileName);
            values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
            values.put(MediaStore.Images.Media.DATA, destFile.getPath());
            mCameraTemp = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraTemp);
            startActivityForResult(intent, REQUEST_CAMERA);
        }
    }
    return true;
}

From source file:ca.ualberta.cmput301w14t08.geochan.fragments.EditFragment.java

/**
 * Allows the user to change the image attached to their comment or remove it
 * entirely. Prompts the user with an AlertDialog as to which option they would like
 * to select. /*  w  ww  .  j  ava 2s.c o  m*/
 * @param view The Button pressed to call editImage.
 */
public void editImage(View view) {
    if (view.getId() == R.id.attach_image_button) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
        dialog.setTitle(R.string.attach_image_title);
        dialog.setMessage(R.string.attach_image_dialog);
        dialog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, "Test"), ImageHelper.REQUEST_GALLERY);
            }
        });
        dialog.setNegativeButton("Camera", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                Intent intent = new Intent();
                intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                try {
                    imageFile = ImageHelper.createImageFile();
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
                    startActivityForResult(Intent.createChooser(intent, "Test"), ImageHelper.REQUEST_CAMERA);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        dialog.setNeutralButton("Remove Image", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                editComment.setImage(null);
                editComment.setImageThumb(null);
            }
        });
        dialog.show();
    }
}

From source file:com.repay.android.frienddetails.FriendDetailsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_settings:
        Intent intent = new Intent();
        intent.setClass(this, SettingsActivity.class);
        startActivity(intent);/*from  w ww.  j  av  a  2s. c  om*/
        return true;

    case R.id.action_delete:
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle(R.string.activity_friendoverview_deletedialog_title);
        dialog.setMessage(R.string.activity_friendoverview_deletedialog_message);

        dialog.setPositiveButton(R.string.activity_friendoverview_deletedialog_yes, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                deleteFriend();
            }
        });

        dialog.setNegativeButton(R.string.activity_friendoverview_deletedialog_no, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.show();
        return true;

    case R.id.action_info:
        AlertDialog.Builder infoDialog = new AlertDialog.Builder(this);
        infoDialog.setTitle(R.string.activity_debtHistoryInfoDialog_title);
        infoDialog.setMessage(mInfoMessage);
        infoDialog.setPositiveButton(R.string.activity_debtHistoryInfoDialog_okayBtn, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        infoDialog.show();
        return true;

    case R.id.action_addDebt:
        Intent i = new Intent();
        i.setClass(this, AddDebtActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt(AddDebtActivity.NO_OF_FRIENDS_SELECTED, 1);
        bundle.putString(AddDebtActivity.REPAY_ID + "1", mFriend.getRepayID());
        i.putExtras(bundle);
        startActivity(i);
        return true;

    case R.id.action_reLinkContact:
        Intent pickContactIntent = new Intent(Intent.ACTION_GET_CONTENT);
        pickContactIntent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
        startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
        return true;

    case R.id.action_unLinkContact:
        mFriend = new Friend(mFriend.getRepayID(), Uri.parse(""), mFriend.getName(), mFriend.getDebt());
        mDB.updateFriendRecord(mFriend);
        return true;
    }

    return false;
}