List of usage examples for android.content Intent ACTION_PICK
String ACTION_PICK
To view the source code for android.content Intent ACTION_PICK.
Click Source Link
From source file:ca.ualberta.cmput301.t03.inventory.AddItemView.java
/** * When the upload photos button is clicked an alert dialog will get created asking the * user if they want to upload a photo or take a photo, either option will result in a returned * bitmap which is handled in onActivityResult. * * Code used:// w w w. j a v a2 s. c o m * http://stackoverflow.com/questions/27874038/how-to-make-intent-chooser-for-camera-or-gallery-application-in-android-like-wha */ private void onUploadPhotosButtonClicked() { final CharSequence[] items = { "Take A Photo", "Choose Photo from Gallery" }; AlertDialog.Builder builder = new AlertDialog.Builder(AddItemView.this); builder.setTitle("Attach Photo!"); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (item == 0) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg"); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); startActivityForResult(intent, REQUEST_IMAGE_CAPTURE); } else if (item == 1) { Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE); } } }); builder.show(); }
From source file:com.money.manager.ex.assetallocation.SecurityListFragment.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); if (this.action.equals(Intent.ACTION_PICK)) { // select the current item and return. Cursor c = (Cursor) l.getItemAtPosition(position); Stock stock = Stock.from(c);// www . ja va 2 s .c o m selectedStockSymbol = stock.getSymbol(); setResultAndFinish(); } }
From source file:org.exoplatform.ui.social.SelectedImageActivity.java
private void backToGallery() { Intent intent = new Intent(Intent.ACTION_PICK); intent.setType(ExoConstants.PHOTO_ALBUM_IMAGE_TYPE); if (DocumentActivity._documentActivityInstance != null) { DocumentActivity._documentActivityInstance.startActivityForResult(intent, ExoConstants.REQUEST_PICK_IMAGE_FROM_GALLERY); } else if (ComposeMessageActivity.composeMessageActivity != null) { ComposeMessageActivity.composeMessageActivity.startActivityForResult(intent, ExoConstants.REQUEST_PICK_IMAGE_FROM_GALLERY); }/*from w w w.ja v a 2 s .c om*/ }
From source file:com.amansoni.tripbook.activity.AddItemActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add); mTripName = (EditText) findViewById(R.id.trip_add_name); mTripName.addTextChangedListener(textWatcher); mTripName.setHint(R.string.hint_trip_name); dateFormat = DateFormat.getMediumDateFormat(this); mStartDatePicker = (TextView) findViewById(R.id.trip_add_start); mStartDatePicker.setText(dateFormat.format(new Date())); mStartDatePicker.setOnTouchListener(dateOnTouchListener); mEndDatePicker = (TextView) findViewById(R.id.trip_add_end); mEndDatePicker.setText(dateFormat.format(new Date())); mEndDatePicker.setOnTouchListener(dateOnTouchListener); mNotes = (EditText) findViewById(R.id.trip_add_notes); mNotes.addTextChangedListener(textWatcher); mCurrentDate = mStartDatePicker;//from w w w .j a v a 2 s .c o m mMainImage = (ImageView) findViewById(R.id.trip_add_main_image); mMainImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, SELECT_PHOTO); } }); // check if its an edit to load the existing data if (getIntent().getExtras() != null) { if (getIntent().getExtras().containsKey("itemKey")) { long itemKey = getIntent().getExtras().getLong("itemKey"); mTripbookItem = new TripBookItemData(this).getItem(itemKey); mTripName.setText(mTripbookItem.getTitle()); mStartDatePicker.setText(mTripbookItem.getCreatedAt()); mEndDatePicker.setText(mTripbookItem.getEndDate()); mNotes.setText(mTripbookItem.getDescription()); ImageWrapper.loadImageFromFile(this, mMainImage, mTripbookItem.getThumbnail(), 400); } else { // check if we need to import a place GooglePlace place = (GooglePlace) getIntent().getExtras().getSerializable("PLACE"); if (place != null) { Log.d(TAG, "Now importing place " + place.toString()); isImport = true; mTripbookItem = new TripBookItem(place.getName(), TripBookItem.TYPE_PLACE); mTripName.setText(mTripbookItem.getTitle()); mNotes.setText(place.getFormatted_address()); mTripbookItem.setLocation(new TbGeolocation(place.getGeometry().getLocation().getLng(), place.getGeometry().getLocation().getLat())); } } if (getIntent().getExtras().containsKey("itemType")) { mItemType = getIntent().getExtras().getString("itemType"); } else { mItemType = TripBookItem.TYPE_TRIP; } } selectedItems = new ArrayList<>(); fragmentFriends = new HorizontalListFragment(); fragmentPlace = new HorizontalListFragment(); fragmentImages = new HorizontalListFragment(); if (mItemType.equals(TripBookItem.TYPE_TRIP)) { replaceListFragment(fragmentFriends, R.id.trip_view_friends, TripBookItem.TYPE_FRIENDS); replaceListFragment(fragmentPlace, R.id.trip_view_places, TripBookItem.TYPE_PLACE); replaceListFragment(fragmentImages, R.id.trip_view_gallery, TripBookItem.TYPE_GALLERY); } else if (mItemType.equals(TripBookItem.TYPE_PLACE)) { replaceListFragment(fragmentPlace, R.id.trip_view_places, TripBookItem.TYPE_TRIP); replaceListFragment(fragmentFriends, R.id.trip_view_friends, TripBookItem.TYPE_FRIENDS); replaceListFragment(fragmentImages, R.id.trip_view_gallery, TripBookItem.TYPE_GALLERY); } else if (mItemType.equals(TripBookItem.TYPE_FRIENDS)) { replaceListFragment(fragmentPlace, R.id.trip_view_places, TripBookItem.TYPE_TRIP); replaceListFragment(fragmentFriends, R.id.trip_view_friends, TripBookItem.TYPE_PLACE); replaceListFragment(fragmentImages, R.id.trip_view_gallery, TripBookItem.TYPE_GALLERY); } isDirty = false; }
From source file:com.krayzk9s.imgurholo.services.DownloadService.java
@Override protected void onHandleIntent(Intent intent) { final NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); ids = intent.getParcelableArrayListExtra("ids"); albumName = "/"; downloaded = 0;// w w w . j a v a2 s . c o m if (ids.size() > 0) { albumName += intent.getStringExtra("albumName") + "/"; File myDirectory = new File( android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), albumName); if (!myDirectory.exists()) { myDirectory.mkdirs(); } } for (int i = 0; i < ids.size(); i++) { try { final String type = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) .split("/")[1]; final String id = ids.get(i).getJSONObject().getString("id"); final String link = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK); Log.d("data", ids.get(i).getJSONObject().toString()); Log.d(ImgurHoloActivity.IMAGE_DATA_TYPE, ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE).split("/")[1]); Log.d("id", ids.get(i).getJSONObject().getString("id")); Log.d(ImgurHoloActivity.IMAGE_DATA_LINK, ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK)); final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setContentTitle(getString(R.string.picture_download)) .setContentText(getString(R.string.download_in_progress)) .setSmallIcon(R.drawable.icon_desaturated); Ion.with(getApplicationContext(), link).progress(new ProgressCallback() { @Override public void onProgress(int i, int i2) { notificationBuilder.setProgress(i2, i, false); } }).write(new File( android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + albumName + id + "." + type)) .setCallback(new FutureCallback<File>() { @Override public void onCompleted(Exception e, File file) { if (file == null) return; downloaded += 1; if (downloaded == ids.size()) { NotificationCompat.Builder notificationComplete = new NotificationCompat.Builder( getApplicationContext()); if (ids.size() == 1) { Intent viewImageIntent = new Intent(Intent.ACTION_VIEW); viewImageIntent.setDataAndType(Uri.fromFile(file), "image/*"); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); PendingIntent viewImagePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), viewImageIntent, 0); PendingIntent sharePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), shareIntent, 0); notificationComplete.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(R.drawable.icon_desaturated) .setContentText(String.format(getString(R.string.download_progress), downloaded)) .setContentIntent(viewImagePendingIntent) .addAction(R.drawable.dark_social_share, getString(R.string.share), sharePendingIntent); } else { Intent i = new Intent(Intent.ACTION_PICK); i.setDataAndType( Uri.fromFile(new File( android.os.Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + albumName)), "image/*"); PendingIntent viewImagePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), i, 0); notificationComplete.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(R.drawable.icon_desaturated).setContentText(String .format(getString(R.string.download_progress), downloaded)) .setContentIntent(viewImagePendingIntent); } notificationManager.cancel(0); notificationManager.cancel(1); notificationManager.notify(1, notificationComplete.build()); } MediaScannerConnection.scanFile(getApplicationContext(), new String[] { android.os.Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + albumName + id + "." + type }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(final String path, final Uri uri) { Log.i("Scanning", String.format("Scanned path %s -> URI = %s", path, uri.toString())); } }); } }); notificationManager.notify(0, notificationBuilder.build()); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }
From source file:ch.uzh.supersede.feedbacklibrary.FeedbackActivity.java
private void galleryIntent() { Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); startActivityForResult(intent, REQUEST_PHOTO); }
From source file:com.money.manager.ex.search.SearchParametersFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) return null; View view = inflater.inflate(R.layout.fragment_search_parameters, container, false); // bind events ButterKnife.bind(this, view); // bind controls viewHolder = new SearchParametersViewHolder(view); initializeUiControlVariables(view);// ww w . j a v a 2 s . com // Account if (mAccountList == null) { LookAndFeelSettings settings = new AppSettings(getContext()).getLookAndFeelSettings(); AccountService accountService = new AccountService(getContext()); mAccountList = accountService.getAccountList(settings.getViewOpenAccounts(), settings.getViewFavouriteAccounts()); mAccountList.add(0, null); for (int i = 0; i <= mAccountList.size() - 1; i++) { if (mAccountList.get(i) != null) { mAccountNameList.add(mAccountList.get(i).getName()); mAccountIdList.add(mAccountList.get(i).getId()); } else { mAccountNameList.add(""); mAccountIdList.add(AdapterView.INVALID_POSITION); } } } // create adapter for spinAccount ArrayAdapter<String> adapterAccount = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, mAccountNameList); adapterAccount.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinAccount.setAdapter(adapterAccount); //Payee viewHolder.txtSelectPayee.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), PayeeActivity.class); intent.setAction(Intent.ACTION_PICK); startActivityForResult(intent, RequestCodes.PAYEE); } }); //Category txtSelectCategory.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), CategoryListActivity.class); intent.setAction(Intent.ACTION_PICK); startActivityForResult(intent, RequestCodes.CATEGORY); } }); // Status if (mStatusItems.size() <= 0) { // add blank row mStatusItems.add(""); mStatusValues.add(SearchParameters.STRING_NULL_VALUE); mStatusItems.addAll(Arrays.asList(getResources().getStringArray(R.array.status_items))); mStatusValues.addAll(Arrays.asList(getResources().getStringArray(R.array.status_values))); } // create adapter for spinnerStatus ArrayAdapter<String> adapterStatus = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, mStatusItems); adapterStatus.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinStatus.setAdapter(adapterStatus); // Date from // viewHolder.txtDateFrom.setOnClickListener(new OnDateButtonClickListener(getActivity(), viewHolder.txtDateFrom)); // Date to // viewHolder.txtDateTo.setOnClickListener(new OnDateButtonClickListener(getActivity(), viewHolder.txtDateTo)); // Store search criteria values into the controls. displaySearchCriteria(view); return view; }
From source file:com.money.manager.ex.assetallocation.SecurityListFragment.java
@Override protected void setResult() { Intent result;/*from w w w . j av a 2 s .c o m*/ switch (this.action) { case Intent.ACTION_PICK: result = new Intent(); result.putExtra(INTENT_RESULT_STOCK_SYMBOL, selectedStockSymbol); if (TextUtils.isEmpty(selectedStockSymbol)) { getActivity().setResult(Activity.RESULT_CANCELED, result); } else { getActivity().setResult(Activity.RESULT_OK, result); } break; default: // otherwise return cancel getActivity().setResult(Activity.RESULT_CANCELED); break; } }
From source file:cn.xcom.helper.activity.AuthorizedActivity.java
private void showPickDialog() { new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT) .setNegativeButton("", new DialogInterface.OnClickListener() { @Override/*w w w . j a v a2 s . c om*/ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent albumIntent = new Intent(); albumIntent.setType("image/*"); albumIntent.setAction(Intent.ACTION_PICK); startActivityForResult(albumIntent, PHOTO_REQUEST_ALBUM); } }).setPositiveButton("?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); int permissionCheck = ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { File path = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); File file = new File(path, "51helper.jpg"); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); } startActivityForResult(cameraIntent, PHOTO_REQUEST_CAMERA); } else if (permissionCheck == PackageManager.PERMISSION_DENIED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) mContext, Manifest.permission.CAMERA)) { // Show an expanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions((Activity) mContext, new String[] { Manifest.permission.CAMERA }, MY_PERMISSIONS_REQUEST_READ_CONTACTS); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } } } }).show(); }