List of usage examples for android.content Intent ACTION_GET_CONTENT
String ACTION_GET_CONTENT
To view the source code for android.content Intent ACTION_GET_CONTENT.
Click Source Link
From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java
private void addImage() { // when clicking attack the user should at first select an application to // choose the image with and then choose an image. // this intent is for getting the image Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT); getIntent.setType("image/*"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) getIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); // and this for getting the application to get the image with Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); pickIntent.setType("image/*"); // and this finally is for opening the chooserIntent for opening the // getIntent for returning the image uri. Yep, thanks android Intent chooserIntent = Intent.createChooser(getIntent, getResources().getString(R.string.select_image)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { pickIntent }); startActivityForResult(chooserIntent, ADD_PHOTO_CLICKED); // nope I don't want to be asked for a pwd when selected the image getActivity().getSharedPreferences(Constants.PREFERENCES, 0).edit().putBoolean(Constants.PWD_REQUEST, false) .apply();//from www . ja v a 2 s . c o m }
From source file:com.example.android.pharmacyinventory.EditorActivity.java
public void openImageSelector() { Intent intent;// w ww . ja v a2s .com if (Build.VERSION.SDK_INT < 19) { intent = new Intent(Intent.ACTION_GET_CONTENT); } else { intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST); }
From source file:org.naturenet.ui.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); userList = FetchData.getInstance().getUsers(); setContentView(R.layout.activity_main); drawer = (DrawerLayout) findViewById(R.id.drawer_layout); toolbar = (Toolbar) findViewById(R.id.toolbar); navigationView = (NavigationView) findViewById(R.id.nav_view); logout = navigationView.getMenu().findItem(R.id.nav_logout); settings = navigationView.getMenu().findItem(R.id.nav_settings); header = navigationView.getHeaderView(0); sign_in = (Button) header.findViewById(R.id.nav_b_sign_in); join = (Button) header.findViewById(R.id.nav_b_join); nav_iv = (ImageView) header.findViewById(R.id.nav_iv); display_name = (TextView) header.findViewById(R.id.nav_tv_display_name); affiliation = (TextView) header.findViewById(R.id.nav_tv_affiliation); licenses = (TextView) navigationView.findViewById(R.id.licenses); setSupportActionBar(toolbar);//from w ww . ja v a 2s . c o m ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); navigationView.setNavigationItemSelectedListener(this); add_observation_button = (ImageView) findViewById(R.id.addObsButton); selectionStack = new Stack<>(); selectedImages = new ArrayList<>(); mFirebase = FirebaseDatabase.getInstance().getReference(); tabLayout = (TabLayout) findViewById(R.id.TabLayout); if (getSupportActionBar() != null) getSupportActionBar().setDisplayShowTitleEnabled(false); //Handle the intent from Firebase Notifications. if (getIntent().getExtras() != null) { Bundle dataBundle = getIntent().getExtras(); //get the parent and context String parent = (String) dataBundle.get("parent"); String context = (String) dataBundle.get("context"); if (parent != null && context != null) { switch (context) { case "observations": Intent observationIntent = new Intent(MainActivity.this, ObservationActivity.class); observationIntent.putExtra("observation", parent); startActivity(observationIntent); break; case "ideas": { final Intent ideaIntent = new Intent(MainActivity.this, IdeaDetailsActivity.class); final ProgressDialog dialog; dialog = ProgressDialog.show(MainActivity.this, "Loading", "", true, false); dialog.show(); mFirebase.child(Idea.NODE_NAME).child(parent) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Idea idea = dataSnapshot.getValue(Idea.class); ideaIntent.putExtra("idea", idea); dialog.dismiss(); startActivity(ideaIntent); } @Override public void onCancelled(DatabaseError databaseError) { Toast.makeText(MainActivity.this, "Could not load Design Idea", Toast.LENGTH_SHORT).show(); } }); break; } case "activities": { final Intent projectIntent = new Intent(MainActivity.this, ProjectActivity.class); final ProgressDialog dialog; dialog = ProgressDialog.show(MainActivity.this, "Loading", "", true, false); dialog.show(); mFirebase.child(Project.NODE_NAME).child(parent) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Project project = dataSnapshot.getValue(Project.class); projectIntent.putExtra("project", project); dialog.dismiss(); startActivity(projectIntent); } @Override public void onCancelled(DatabaseError databaseError) { Toast.makeText(MainActivity.this, "Could not load New Project", Toast.LENGTH_SHORT).show(); } }); break; } } } } //Set listener for the tab layout tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { //Position for the map view if (tab.getPosition() == 0) { getFragmentManager().popBackStack(); getFragmentManager().beginTransaction() .replace(R.id.fragment_container, ExploreFragment.newInstance(user_home_site)) .addToBackStack(ExploreFragment.FRAGMENT_TAG).commit(); } //Position for the gallery view else if (tab.getPosition() == 1) { getFragmentManager().popBackStack(); getFragmentManager().beginTransaction() .replace(R.id.fragment_container, new ObservationGalleryFragment()) .addToBackStack(ObservationGalleryFragment.FRAGMENT_TAG).commit(); } } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); licenses.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(v.getContext()) .setView(View.inflate(MainActivity.this, R.layout.about, null)) .setNegativeButton("Dismiss", null).setCancelable(false).show(); } }); this.invalidateOptionsMenu(); /** * When user selects the camera icon, check to see if we have permission to view their images. */ add_observation_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_CODE_GALLERY); } else { setGallery(); } select.setVisibility(View.GONE); dialog_add_observation.setVisibility(View.VISIBLE); } }); sign_in.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (((NatureNetApplication) getApplication()).isConnected()) { MainActivity.this.goToLoginActivity(); } else { Toast.makeText(MainActivity.this, R.string.no_connection, Toast.LENGTH_SHORT).show(); } } }); join.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (((NatureNetApplication) getApplication()).isConnected()) { MainActivity.this.goToJoinActivity(); } else { Toast.makeText(MainActivity.this, R.string.no_connection, Toast.LENGTH_SHORT).show(); } } }); showNoUser(); getFragmentManager().beginTransaction().add(R.id.fragment_container, new LaunchFragment()).commit(); mUserAuthSubscription = ((NatureNetApplication) getApplication()).getCurrentUserObservable() .subscribe(new Consumer<Optional<Users>>() { @Override public void accept(Optional<Users> user) throws Exception { if (user.isPresent()) { onUserSignIn(user.get()); if (getFragmentManager().getBackStackEntryCount() == 0) { getFragmentManager().beginTransaction() .add(R.id.fragment_container, ExploreFragment.newInstance(user_home_site)) .commitAllowingStateLoss(); } tabLayout.setVisibility(View.VISIBLE); } else { if (signed_user != null) { onUserSignOut(); } showNoUser(); } } }); //click listener for when user selects profile image nav_iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (signed_user != null) goToProfileSettingsActivity(); } }); display_name.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (signed_user != null) goToProfileSettingsActivity(); } }); affiliation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (signed_user != null) goToProfileSettingsActivity(); } }); mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(10000); mLocationRequest.setFastestInterval(5000); mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder() .addLocationRequest(mLocationRequest); mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API) .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build(); PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi .checkLocationSettings(mGoogleApiClient, builder.build()); result.setResultCallback(new ResultCallback<LocationSettingsResult>() { @Override public void onResult(@NonNull LocationSettingsResult locationSettingsResult) { final Status status = locationSettingsResult.getStatus(); if (status.getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) { try { status.startResolutionForResult(MainActivity.this, REQUEST_CODE_CHECK_LOCATION_SETTINGS); } catch (IntentSender.SendIntentException e) { Timber.w(e, "Unable to resolve location settings"); } } else if (status.getStatusCode() == LocationSettingsStatusCodes.SUCCESS) { requestLocationUpdates(); } } }); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { Location lastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (lastLocation != null) { latValue = lastLocation.getLatitude(); longValue = lastLocation.getLongitude(); } } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_CODE_CHECK_LOCATION_SETTINGS); } latValue = 0.0; longValue = 0.0; dialog_add_observation = (LinearLayout) findViewById(R.id.ll_dialog_add_observation); add_observation_cancel = (ImageView) findViewById(R.id.dialog_add_observation_iv_cancel); camera = (Button) findViewById(R.id.dialog_add_observation_b_camera); gallery = (Button) findViewById(R.id.dialog_add_observation_b_gallery); select = (TextView) findViewById(R.id.dialog_add_observation_tv_select); gridview = (GridView) findViewById(R.id.dialog_add_observation_gv); gallery_item = (ImageView) findViewById(R.id.gallery_iv); cameraPhoto = new CameraPhoto(this); galleryPhoto = new GalleryPhoto(this); add_observation_cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { selectedImages.clear(); select.setVisibility(View.GONE); dialog_add_observation.setVisibility(View.GONE); } }); /** * Click listener for when user selects images they want to upload. */ select.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Picasso.with(MainActivity.this).cancelTag(ImageGalleryAdapter.class.getSimpleName()); setGallery(); goToAddObservationActivity(false); } }); camera.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isStoragePermitted()) { setGallery(); select.setVisibility(View.GONE); try { startActivityForResult(cameraPhoto.takePhotoIntent(), REQUEST_CODE_CAMERA); } catch (IOException e) { Toast.makeText(MainActivity.this, "Something Wrong while taking photo", Toast.LENGTH_SHORT) .show(); } } else Toast.makeText(MainActivity.this, R.string.permission_rejected, Toast.LENGTH_LONG).show(); } }); gallery.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isStoragePermitted()) { select.setVisibility(View.GONE); selectedImages.clear(); //Check to see if the user is on API 18 or above. if (usingApiEighteenAndAbove()) { Intent intent = new Intent(); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY_IMAGES); } else { //If not on 18 or above, go to the custom Gallery Activity Intent intent = new Intent(getApplicationContext(), ImagePicker.class); startActivityForResult(intent, IMAGE_PICKER_RESULTS); } } else Toast.makeText(MainActivity.this, R.string.permission_rejected, Toast.LENGTH_LONG).show(); } }); dialog_add_observation.setVisibility(View.GONE); }
From source file:org.andstatus.app.TimelineActivity.java
/** * Listener that checks for clicks on the main list view. * // w ww.ja va 2 s. c o m * @param adapterView * @param view * @param position * @param id */ @Override public void onItemClick(AdapterView<?> adapterView, final View view, final int position, final long id) { if (id <= 0) { if (MyLog.isLoggable(this, MyLog.VERBOSE)) { MyLog.v(this, "onItemClick, position=" + position + "; id=" + id + "; view=" + view); } return; } new AsyncTask<Void, Void, Uri>() { @Override protected Uri doInBackground(Void... params) { long linkedUserId = getLinkedUserIdFromCursor(position); MyAccount ma = MyContextHolder.get().persistentAccounts().getAccountWhichMayBeLinkedToThisMessage( id, linkedUserId, mListParametersNew.myAccountUserId); if (MyLog.isLoggable(this, MyLog.VERBOSE)) { MyLog.v(this, "onItemClick, position=" + position + "; id=" + id + "; view=" + view + "; linkedUserId=" + linkedUserId + " account=" + ma.getAccountName()); } return MyProvider.getTimelineMsgUri(ma.getUserId(), mListParametersNew.getTimelineType(), true, id); } @Override protected void onPostExecute(Uri uri) { String action = getIntent().getAction(); if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) { if (MyLog.isLoggable(this, MyLog.DEBUG)) { MyLog.d(this, "onItemClick, setData=" + uri); } setResult(RESULT_OK, new Intent().setData(uri)); } else { if (MyLog.isLoggable(this, MyLog.DEBUG)) { MyLog.d(this, "onItemClick, startActivity=" + uri); } startActivity(new Intent(Intent.ACTION_VIEW, uri)); } } }.execute(); }
From source file:com.fabernovel.alertevoirie.ReportDetailsActivity.java
private void takePicture(int type, int RequestCode) { // Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File tmpFile = null;/* w w w . j ava 2s . co m*/ try { tmpFile = File.createTempFile("capture", ".tmp"); } catch (IOException e) { e.printStackTrace(); } Intent camIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); uriOfPicFromCamera = Uri.fromFile(tmpFile); camIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriOfPicFromCamera); Intent gallIntent = new Intent(); gallIntent.setType("image/*"); gallIntent.setAction(Intent.ACTION_GET_CONTENT); if (type == 0) { ReportDetailsActivity.this.startActivityForResult(camIntent, RequestCode); } else if (type == 1) { ReportDetailsActivity.this.startActivityForResult(Intent.createChooser(gallIntent, "Galerie photo"), RequestCode); } // startActivityForResult(intent, v.getId()); }
From source file:spring16.cs442.com.obtchat_10.BluetoothChatFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // action with ID action_refresh was selected case R.id.chat_window_action_search: //Toast.makeText(this, "Search selected", Toast.LENGTH_SHORT) // .show(); Intent serverIntent = new Intent(self, Device_List.class); startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE); break;/*w w w.j a va 2s .c om*/ // action with ID action_settings was selected case R.id.chat_window_action_settings: selectImage(); break; case R.id.action_file_attach: if (null != deviceAddressMap.get(dev_name)) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivityForResult(intent, 44); } else { Toast.makeText(self, "Not connected to any device", Toast.LENGTH_SHORT).show(); } break; default: break; } return true; }
From source file:uno.weichen.abnd10_inventoryapp.DetailActivity.java
public void openImageSelector(View view) { Intent intent;// w ww. j a va2 s .c om if (Build.VERSION.SDK_INT < 19) { intent = new Intent(Intent.ACTION_GET_CONTENT); } else { intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST); }
From source file:ca.rmen.android.scrumchatter.main.MainActivity.java
private void startFileChooser() { final Intent importIntent; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) importIntent = new Intent(Intent.ACTION_GET_CONTENT); else//from w ww. j ava2s . c o m importIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); importIntent.setType("*/*"); importIntent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(Intent.createChooser(importIntent, getResources().getText(R.string.action_import)), ACTIVITY_REQUEST_CODE_IMPORT); }
From source file:com.bai.android.ui.OtherActivity.java
public void changeAvatar() { // Prompt the user to select image from gallery or camera. alertDialog = new AlertDialog.Builder(OtherActivity.this); alertDialog.setMessage(getResources().getString(R.string.select_image_source)); alertDialog.setPositiveButton(getResources().getString(R.string.gallery), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // remove the dialog to prevent "leakage" dialog.dismiss();/*from w w w.j a v a2s . co m*/ Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null); intent.setType("image/*"); startActivityForResult(intent, GALLERY_IMAGE_ACTIVITY_REQUEST_CODE); } }); alertDialog.setNeutralButton(getResources().getString(R.string.camera), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Uri imageUri = getOutputMediaFileUri(); // create a file to save the image if (imageUri != null) { SharedPreferences.Editor prefEditor = getSharedPreferences(SHR_PRF_APP_KEY, MODE_PRIVATE).edit(); prefEditor.putString(SHR_PRF_IMG_URI, imageUri.getPath()); prefEditor.commit(); prefEditor = null; Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); // set the image file name // start the image capture Intent startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); } } }); alertDialog.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // close this dialog dialog.dismiss(); } }); alertDialog.show(); }