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.projectattitude.projectattitude.Activities.ViewProfileActivity.java
/** * Initial set up on creation including setting up references, adapters, and readying the search * button./*from w w w .j a va2 s . c o m*/ * @param savedInstanceState */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_profile); searchBar = (EditText) findViewById(R.id.searchBar); searchButton = (Button) findViewById(R.id.searchButton); removeButton = (Button) findViewById(R.id.removeButton); image = (ImageView) findViewById(R.id.profileImage); nameView = (TextView) findViewById(R.id.profileUname); recentMoodView = (ListView) findViewById(R.id.latestMood); followUserList = (ListView) findViewById(R.id.followList); followedUserList = (ListView) findViewById(R.id.followedList); recentMoodAdapter = new MoodMainAdapter(this, recentMoodList); recentMoodView.setAdapter(recentMoodAdapter); user = userController.getActiveUser(); followUserAdapter = new ArrayAdapter<String>(this, R.layout.list_item, user.getFollowList()); followedUserAdapter = new ArrayAdapter<String>(this, R.layout.list_item, user.getFollowedList()); followUserList.setAdapter(followUserAdapter); followedUserList.setAdapter(followedUserAdapter); searchButton.setOnClickListener(new View.OnClickListener() { // adding a new user to following list @Override public void onClick(View v) { String followingName = searchBar.getText().toString(); User followedUser = new User(); followedUser.setUserName(followingName); if (followingName.equals("")) { // no username entered to search for searchBar.requestFocus(); // search has been canceled } else { if (isNetworkAvailable()) { ElasticSearchUserController.GetUserTask getUserTask = new ElasticSearchUserController.GetUserTask(); try { if (getUserTask.execute(followedUser.getUserName()).get() == null) { Log.d("Error", "User did not exist"); Toast.makeText(ViewProfileActivity.this, "User not found.", Toast.LENGTH_SHORT) .show(); } else { Log.d("Error", "User did exist"); //grab user from db and add to following list getUserTask = new ElasticSearchUserController.GetUserTask(); try { followedUser = getUserTask.execute(followingName).get(); if (followedUser != null) { // user exists if (followedUser.getUserName().equals(user.getUserName())) { Toast.makeText(ViewProfileActivity.this, "You cannot be friends with yourself. Ever", Toast.LENGTH_SHORT) .show(); } else { if (user.getFollowList().contains(followedUser.getUserName())) { Toast.makeText(ViewProfileActivity.this, "You're already following that user.", Toast.LENGTH_SHORT) .show(); } else {// user not already in list //check if request between users already exists in database boolean isContained = false; ArrayList<FollowRequest> requests = followedUser.getRequests(); for (int i = 0; i < followedUser.getRequests().size(); i++) { //Checks if request already exists if (requests.get(i).getRequester().equals(user.getUserName()) && requests.get(i).getRequestee() .equals(followedUser.getUserName())) { isContained = true; break; } } if (!isContained) { //request doesn't exists - not sure why .get always returns an filled array or empty array followedUser.getRequests().add(new FollowRequest( user.getUserName(), followedUser.getUserName())); ElasticSearchRequestController.UpdateRequestsTask updateRequestsTask = new ElasticSearchRequestController.UpdateRequestsTask(); updateRequestsTask.execute(followedUser); Toast.makeText(ViewProfileActivity.this, "Request sent!", Toast.LENGTH_SHORT).show(); } else { // request exists Toast.makeText(ViewProfileActivity.this, "Request already exists.", Toast.LENGTH_SHORT).show(); } } } } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } else { Toast.makeText(ViewProfileActivity.this, "Must be connected to internet to search for users!", Toast.LENGTH_LONG).show(); } } } }); //On-click for removeButton removeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String followingName = searchBar.getText().toString(); if (followingName.equals("")) { // no username entered to search for searchBar.requestFocus(); // search has been canceled } else { if (isNetworkAvailable()) { if (!user.getFollowList().contains(followingName)) { //If user not in following list Log.d("Error", "Invalid user."); Toast.makeText(ViewProfileActivity.this, "Invalid user. User not found.", Toast.LENGTH_SHORT).show(); } else { Log.d("Error", "Followed User exists"); setResult(RESULT_OK); //remove followedList of who user is following try { ElasticSearchUserController.GetUserTask getUserTask = new ElasticSearchUserController.GetUserTask(); User followedUser = getUserTask.execute(followingName).get(); if (followedUser != null) { //Remove followee and update database followedUser.getFollowedList().remove(user.getUserName()); ElasticSearchUserController.UpdateUserRequestFollowedTask updateUserRequestFollowedTask = new ElasticSearchUserController.UpdateUserRequestFollowedTask(); updateUserRequestFollowedTask.execute(followedUser); } } catch (Exception e) { e.printStackTrace(); } //user exists --> delete follower and update database user.removeFollow(followingName); ElasticSearchUserController.UpdateUserRequestTask updateUserRequestTask = new ElasticSearchUserController.UpdateUserRequestTask(); updateUserRequestTask.execute(user); Toast.makeText(ViewProfileActivity.this, "Followed user has been removed!", Toast.LENGTH_SHORT).show(); followUserAdapter.notifyDataSetChanged(); } } else { Toast.makeText(ViewProfileActivity.this, "Must be connected to internet to remove user!", Toast.LENGTH_LONG).show(); } } } }); //If image exists in user, set image if (user.getPhoto() != null && user.getPhoto().length() > 0) { //decode base64 image stored in User byte[] imageBytes = Base64.decode(user.getPhoto(), Base64.DEFAULT); Bitmap decodedImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); image.setImageBitmap(decodedImage); } /** * This handles when a user clicks on their most recent mood, taking them to the view mood screen */ recentMoodView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intentView = new Intent(ViewProfileActivity.this, ViewMoodActivity.class); intentView.putExtra("mood", recentMoodList.get(position)); startActivityForResult(intentView, 1); } }); //Adjusted from http://codetheory.in/android-pick-select-image-from-gallery-with-intents/ //on 3/29/17 /** * This handles when the user clicks on their image */ image.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Check if user has permission to get picture from gallery if (ContextCompat.checkSelfPermission(thisActivity, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(thisActivity, new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); } else { //user already has permission Intent intent = new Intent(); // Show only images, no videos or anything else intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); // Always show the chooser (if there are multiple options available) startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1); } } }); }
From source file:uk.ac.horizon.artcodes.activity.ExperienceEditActivity.java
private void selectImage(int request_id) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); if (intent.resolveActivity(getPackageManager()) != null) { startActivityForResult(intent, request_id); }/* www . j a v a2 s .co m*/ }
From source file:net.jongrakko.zipsuri.activity.PostReviseActivity.java
private void pickImage() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivityForResult(intent, PICK_PHOTO_FOR_AVATAR); }
From source file:br.com.anteros.vendas.gui.AnexoCadastroActivity.java
/** * Seleciona um arquivo do tipo imagem para anexar *//*from w w w.j a va2 s. c o m*/ private void selecionarImagem() { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Selecione"), SELECIONAR_ARQUIVO); }
From source file:com.zhihuigu.sosoOffice.RegisterThirdActivity.java
@Override public void onClick(View v) { if (v == backBtn) { Intent intent = new Intent(this, LoginActivity.class); startActivity(intent);//from w w w . j av a2s. c o m finish(); } else if (v == submitBtn) { if (textValidate()) { new Thread(runnable).start(); } } else if (v == linearGetImage) { int height = MyApplication.getInstance(this).getScreenHeight(); if (photo_tag) { shareBtn3.setVisibility(View.VISIBLE); if (height == 1280) { chazhi = 670; } else if (height == 800) { chazhi = 340; } else if (height == 960) { chazhi = 500; } else if (height == 854) { chazhi = 400; } else if (height == 480) { chazhi = 175; } } else { shareBtn3.setVisibility(View.GONE); if (height == 1280) { chazhi = 800; } else if (height == 800) { chazhi = 440; } else if (height == 960) { chazhi = 600; } else if (height == 854) { chazhi = 492; } else if (height == 480) { chazhi = 240; } } CommonUtils.hideSoftKeyboard(this);// new Thread(runnableForShowDialog).start(); } else if (v == shareBtn1) { dismiss(); Intent openCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); fileName = CommonUtils.getFileName(); MyApplication.getInstance(this).setFileName(fileName); File file = new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD); if (!file.exists()) { file.mkdirs(); } if (CommonUtils.isHasSdcard()) { openCamera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD, fileName))); } startActivityForResult(openCamera, REQUEST_CODE_TAKE_PICTURE); } else if (v == shareBtn2) { dismiss(); Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT); getAlbum.setType(IMAGE_TYPE); startActivityForResult(getAlbum, IMAGE_CODE); } else if (v == shareBtn3) { dismiss(); // Intent intent = new Intent(this,ImagePreViewActivity.class); // intent.putExtra("path", path); // startActivityForResult(intent, 6); ArrayList<String> al = new ArrayList<String>(); al.clear(); al.add(path); Intent it = new Intent(this, ImageSwitcher.class); it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); it.putStringArrayListExtra("pathes", al); it.putExtra("index", 0); startActivity(it); } else if (v == cancleBtn) { dismiss(); } super.onClick(v); }
From source file:com.google.android.apps.muzei.gallery.GallerySettingsActivity.java
private void requestGetContent(ActivityInfo info) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); intent.setClassName(info.packageName, info.name); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); startActivityForResult(intent, REQUEST_CHOOSE_PHOTOS); }
From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java
private void showAudioFileChooser() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("audio/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); try {/* w w w .j a va 2 s .c om*/ startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), AUDIO_REQUEST); } catch (android.content.ActivityNotFoundException ex) { // Potentially direct the user to the Market with a Dialog Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show(); } }
From source file:com.brandroidtools.filemanager.activities.PickerActivity.java
private boolean isFilePickIntent(Intent intent) { final String action = intent.getAction(); if (Intent.ACTION_GET_CONTENT.equals(action)) { return true; }//from w w w . ja va2s .c o m if (Intent.ACTION_PICK.equals(action)) { final Uri data = intent.getData(); if (data != null && FILE_URI_SCHEME.equals(data.getScheme())) { return true; } } return false; }
From source file:org.alfresco.mobile.android.application.manager.ActionManager.java
/** * Allow to pick file with other apps./*from w w w .ja v a 2s. c o m*/ * * @return Activity for Result. */ public static void actionPickFile(Fragment f, int requestCode) { try { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.setType("*/*"); i.addCategory(Intent.CATEGORY_OPENABLE); f.startActivityForResult(Intent.createChooser(i, f.getText(R.string.content_app_pick_file)), requestCode); } catch (ActivityNotFoundException e) { MessengerManager.showToast(f.getActivity(), R.string.error_unable_open_file); } }