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.trigger_context.conf.Set_File_Select.java

private void showFileChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {/*from  w ww .j  a v a2 s  .co  m*/
        startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
    } 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:java_lang_programming.com.android_media_demo.article94.java.ImageDecoderActivity.java

/**
 * start ExternalApps if the required READ_EXTERNAL_STORAGE permission has been granted.
 *//*www  . jav  a2s .  c o m*/
private void startExternalAppSelectableImage() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

    // Filter to only show results that can be "opened", such as a
    // file (as opposed to a list of contacts or timezones)
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/*");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        intent.putExtra(Intent.EXTRA_MIME_TYPES, types.toArray());
    }
    startActivityForResult(Intent.createChooser(intent, null), ImageSelectionDemoActivity.REQUEST_CODE_CHOOSER);
}

From source file:com.ultramegasoft.flavordex2.util.PhotoUtils.java

/**
 * Get an Intent to select a photo from the gallery.
 *
 * @return Get content Intent//from   w  ww  .j ava 2 s  .c  o  m
 */
@NonNull
public static Intent getSelectPhotoIntent() {
    final Intent intent;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    } else {
        intent = new Intent(Intent.ACTION_GET_CONTENT);
    }
    intent.setType("image/*");
    return intent;
}

From source file:com.duy.ascii.sharedcode.image.ImageToAsciiActivity.java

private void selectImage() {
    if (!permissionGrated()) {
        return;/*from  w  w  w . ja v  a2s. c  om*/
    }
    Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
    getIntent.setType("image/*");
    Intent pickIntent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    pickIntent.setType("image/*");
    Intent chooserIntent = Intent.createChooser(getIntent, "Select Image");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { pickIntent });
    startActivityForResult(chooserIntent, PICK_IMAGE);
}

From source file:com.karthiknr.visionid.MainActivity.java

protected void startGalleryActivity() {
    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:com.example.android.wifidirect.DeviceDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mContentView = inflater.inflate(R.layout.device_detail, null);
    mContentView.findViewById(R.id.btn_connect).setOnClickListener(new View.OnClickListener() {

        @Override//from w ww  .j a va2  s  . co m
        public void onClick(View v) {
            WifiP2pConfig config = new WifiP2pConfig();
            config.deviceAddress = device.deviceAddress;
            config.wps.setup = WpsInfo.PBC;
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
            progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
                    "Connecting to :" + device.deviceAddress, true, true
            //                        new DialogInterface.OnCancelListener() {
            //
            //                            @Override
            //                            public void onCancel(DialogInterface dialog) {
            //                                ((DeviceActionListener) getActivity()).cancelDisconnect();
            //                            }
            //                        }
            );
            ((DeviceActionListener) getActivity()).connect(config);

        }
    });

    mContentView.findViewById(R.id.btn_send_data);

    mContentView.findViewById(R.id.btn_disconnect).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((DeviceActionListener) getActivity()).disconnect();
        }
    });

    mContentView.findViewById(R.id.btn_start_client).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // Allow user to pick an image from Gallery or other
            // registered apps
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("image/*");
            startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
        }
    });

    return mContentView;
}

From source file:org.intakers.intake.helper.SelectImageActivity.java

public void selectImageInAlbum(View view) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(intent, REQUEST_SELECT_IMAGE_IN_ALBUM);
    }/*from  w  ww .  j a  v  a2  s. c  o  m*/
}

From source file:com.normalexception.app.rx8club.fragment.StylerFragment.java

@Override
public void onClick(View arg0) {
    TextView tv = (TextView) ViewHolder.get(arg0.getRootView(), R.id.postBox);

    if (tv == null) {
        Log.e(TAG, "TextView is null...", null);
        return;/*from  w  w w  .j  a v  a  2 s. c  om*/
    }

    String val = "";

    switch (arg0.getId()) {
    case R.id.boldButton:
        val = VBForumLocale.getStyle(Style.BOLD);
        break;
    case R.id.italicButton:
        val = VBForumLocale.getStyle(Style.ITALIC);
        break;
    case R.id.underlineButton:
        val = VBForumLocale.getStyle(Style.UNDERLINE);
        break;
    case R.id.linkCodeButton:
        val = VBForumLocale.getStyle(Style.URL);
        break;
    case R.id.imageCodeButton:
        val = VBForumLocale.getStyle(Style.IMAGE);
        break;
    case R.id.quoteCodeButton:
        val = VBForumLocale.getStyle(Style.QUOTE);
        break;
    case R.id.emoticonButton:
        EmoticonDialog ed = new EmoticonDialog(getActivity(), tv);
        ed.show();
        break;
    case R.id.attachButton:
        /*Intent i = new Intent(
              Intent.ACTION_PICK, 
              android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);                   
        startActivityForResult(i, RESULT_LOAD_IMAGE);*/
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        getActivity().startActivityForResult(Intent.createChooser(intent, "Select Picture"), RESULT_LOAD_IMAGE);
        break;
    }

    if (!val.equals(""))
        tv.setText(tv.getText().toString() + val);
}

From source file:ca.ggolda.lendit.fragments.FragChat.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.activity_chat, container, false);

    // Get UserID
    mFirebaseAuth = FirebaseAuth.getInstance();
    FirebaseUser user = mFirebaseAuth.getCurrentUser();
    UserID = user.getUid();/*from   w  w w . j  a va2 s. c  om*/
    mUsername = user.getDisplayName();

    mUsername = ANONYMOUS;

    mFirebaseDatabase = FirebaseDatabase.getInstance();

    mUsername = user.getDisplayName();

    mFirebaseStorage = FirebaseStorage.getInstance();

    mMessagesDatabaseReference = mFirebaseDatabase.getReference().child("messages");
    mChatPhotosStorageReference = mFirebaseStorage.getReference().child("chat_photos");

    // Initialize references to views
    mProgressBar = (ProgressBar) v.findViewById(R.id.progressBar);
    mMessageListView = (ListView) v.findViewById(R.id.messageListView);
    mPhotoPickerButton = (ImageButton) v.findViewById(R.id.photoPickerButton);
    mMessageEditText = (EditText) v.findViewById(R.id.messageEditText);
    mSendButton = (Button) v.findViewById(R.id.sendButton);

    // Initialize message ListView and its adapter
    List<InstanceMessage> friendlyMessages = new ArrayList<>();
    mMessageAdapter = new AdapterMessages(getContext(), R.layout.message_slide, friendlyMessages);
    mMessageListView.setAdapter(mMessageAdapter);

    // Initialize progress bar
    mProgressBar.setVisibility(ProgressBar.INVISIBLE);

    // ImagePickerButton shows an image picker to upload a image for a message
    mPhotoPickerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("image/jpeg");
            intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
            startActivityForResult(Intent.createChooser(intent, "Complete action using"), RC_PHOTO_PICKER);
        }
    });

    // Enable Send button when there's text to send
    mMessageEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if (charSequence.toString().trim().length() > 0) {
                mSendButton.setEnabled(true);
            } else {
                mSendButton.setEnabled(false);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT) });

    // Send button sends a message and clears the EditText
    mSendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // TODO: Send messages on click

            InstanceMessage friendlyMessage = new InstanceMessage(mMessageEditText.getText().toString(),
                    mUsername, null);

            mMessagesDatabaseReference.push().setValue(friendlyMessage);

            // Clear input box
            mMessageEditText.setText("");
        }
    });

    mChildEventListener = new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            InstanceMessage friendlyMessage = dataSnapshot.getValue(InstanceMessage.class);
            mMessageAdapter.add(friendlyMessage);
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {
        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    };
    mMessagesDatabaseReference.addChildEventListener(mChildEventListener);

    mAuthStateListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {

            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                //user signed in
                OnSignedInInitialise(user.getDisplayName());
            } else {
                //user signed out
                OnSignedOutCleanUp();
                startActivityForResult(
                        AuthUI.getInstance().createSignInIntentBuilder()
                                .setProviders(AuthUI.EMAIL_PROVIDER, AuthUI.GOOGLE_PROVIDER).build(),
                        RC_SIGN_IN);
            }

        }
    };

    return v;
}

From source file:com.example.shinelon.ocrcamera.MainActivity.java

@Override
public void onClick(View view) {
    switch (view.getId()) {
    //// ww  w .j  av  a 2s.c  o  m
    case R.id.gallery_bt:
        Intent intent2 = new Intent(Intent.ACTION_GET_CONTENT);
        intent2.setType("image/*");
        startActivityForResult(intent2, SELECT);
        break;
    case R.id.txt_bt:
        OCRRecognitionTask task = new OCRRecognitionTask();
        task.execute();
        break;
    case R.id.camera_bt:
        //?
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //putExtra()????
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mUri);
        startActivityForResult(intent, REQUEST_CAMERA);
        break;
    case R.id.crop_bt:
        //??
        crop(getUri());
        break;
    default:
        break;
    }
}