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.magizdev.babyoneday.profilewizard.AvatarFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(com.magizdev.babyoneday.R.layout.fragment_profilewizard_avatar, container,
            false);//from   ww  w. j a va  2s  .c o m
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());

    mAvatarBtn = (ImageButton) rootView.findViewById(com.magizdev.babyoneday.R.id.profile_pic);
    Bitmap avatar = (Bitmap) mPage.getData().getParcelable(Profile.AVATAR);
    if (avatar != null) {
        mAvatarBtn.setBackgroundDrawable(new BitmapDrawable(avatar));
    }
    mAvatarBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
            galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
            galleryIntent.setType("image/*");
            startActivityForResult(galleryIntent, IMAGE_REQUEST_CODE);
        }
    });
    return rootView;
}

From source file:com.albedinsky.android.support.intent.VideoIntent.java

/**
 * Creates a new instance of Intent with {@link Intent#ACTION_GET_CONTENT} and
 * {@link MimeType#VIDEO} MIME type that can be used to launch a gallery app (depends on user's
 * choice) to pick one of available videos.
 *
 * @return New gallery intent instance./*from   w w  w.jav a  2  s. c om*/
 */
@NonNull
public static Intent createGalleryIntent() {
    return new Intent(Intent.ACTION_GET_CONTENT).setType(MimeType.VIDEO);
}

From source file:com.owncloud.android.ui.dialog.UploadSourceDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    String[] allTheItems = { getString(R.string.actionbar_upload_files),
            getString(R.string.actionbar_upload_from_apps) };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.actionbar_upload);
    builder.setItems(allTheItems, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            if (item == 0) {
                Intent action = new Intent(getActivity(), UploadFilesActivity.class);
                action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, ((FileActivity) getActivity()).getAccount());
                //startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
                // this flow seems broken;
                // Actionbarsherlock, maybe?
                getActivity().startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);

            } else if (item == 1) {
                Intent action = new Intent(Intent.ACTION_GET_CONTENT);
                action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
                //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                    action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                }/*from  ww w.j a  v a  2 s  .co  m*/
                //startActivityForResult(   // this flow seems broken;
                // Actionbarsherlock, maybe?
                getActivity().startActivityForResult(
                        Intent.createChooser(action, getString(R.string.upload_chooser_title)),
                        ACTION_SELECT_CONTENT_FROM_APPS);
            }
        }
    });
    return builder.create();
}

From source file:com.gelecekonline.android.uploadornek.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    selectedImageView = (ImageView) findViewById(R.id.selectedImageView);
    selectImageButton = (Button) findViewById(R.id.selectImageButton);
    selectImageButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                //Resim secen Intent tanimlamasi
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, getString(R.string.select_image)),
                        SELECT_IMAGE_INTENT_ID);
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), getString(R.string.select_image_problem),
                        Toast.LENGTH_LONG).show();
            }/*ww  w  . ja  va2s.co  m*/
        }
    });

    uploadButton = (Button) findViewById(R.id.uploadButton);
    uploadButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (selectedImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), getString(R.string.please_select_image),
                        Toast.LENGTH_LONG).show();
            } else {
                dialog = ProgressDialog.show(MainActivity.this, getString(R.string.image_uploading),
                        getString(R.string.please_wait), true);
                if (uploadImageTask == null || uploadImageTask.getStatus() == AsyncTask.Status.FINISHED) {
                    uploadImageTask = new UploadImageTask();
                }
                uploadImageTask.execute();
            }
        }
    });
}

From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.SendPK.java

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

    View view = inflater.inflate(R.layout.dialog_send_pk, container);

    Intent i = getActivity().getIntent();
    Bundle b = i.getExtras();//from   w  w  w  . j  a v  a 2 s.co  m
    safe_lid = b.getString(Safe.P_SAFE_LID);

    peer = D_Peer.getPeerByLID(safe_lid, true, false);
    if (peer == null) {
        Toast.makeText(getActivity(), "No peer. Reload!", Toast.LENGTH_SHORT).show();
        //finish();
    }

    exportByPhoto = (Button) view.findViewById(R.id.dialog_send_pk_export_by_picture);
    sendVia = (Button) view.findViewById(R.id.dialog_send_pk_send_via);

    getDialog().setTitle("Export public key");

    exportByPhoto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (Build.VERSION.SDK_INT < 19) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(intent, SELECT_PHOTO);

                FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                ft.detach(SendPK.this);
                ft.commit();
            } else {
                Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                intent.setType("image/*");
                startActivityForResult(intent, SELECT_PHOTO_KITKAT);
                FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                ft.detach(SendPK.this);
                ft.commit();
            }
        }
    });

    sendVia.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (peer == null) {
                Toast.makeText(getActivity(), "No peer. Reload!", Toast.LENGTH_SHORT).show();
                return;
                //finish();
            }
            //DD_Address adr = new DD_Address(peer);

            String msgBody = DD.getExportTextObjectBody(peer); //adr.getBytes());

            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_TEXT, msgBody); //Safe.SAFE_TEXT_MY_BODY_SEP + Util.stringSignatureFromByte(adr.getBytes()));
            /*
                        String slogan = peer.getSlogan_MyOrDefault();
                        if (slogan == null) slogan = "";
                        else slogan = "\""+slogan+"\"";
                        i.putExtra(Intent.EXTRA_SUBJECT, "DDP2P: Safe Address of \""+peer.getName()+"\",  "+slogan+Safe.SAFE_TEXT_MY_HEADER_SEP);
            */
            i.putExtra(Intent.EXTRA_SUBJECT, DD.getExportTextObjectTitle(peer));
            i = Intent.createChooser(i, "send Public key");
            startActivity(i);
            FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
            ft.detach(SendPK.this);
            ft.commit();
        }
    });

    return view;
}

From source file:com.saltedge.sdk.webview.SEWebViewTools.java

private void pickFile() {
    Intent chooserIntent = new Intent(Intent.ACTION_GET_CONTENT);
    chooserIntent.setType("file/*");
    activity.startActivityForResult(chooserIntent, SEConstants.FILECHOOSER_RESULT_CODE);
}

From source file:com.wodify.cordova.plugin.filepicker.FilePicker.java

/**
 * Pick file from device./*  w  ww. j a  va 2 s.c o  m*/
 */
public void pickFile() {
    Intent intent = new Intent();

    // Any type of file may be picked
    intent.setType("*/*");

    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    if (this.cordova != null) {
        this.cordova.startActivityForResult((CordovaPlugin) this, Intent.createChooser(intent, "Pick File"), 0);
    }
}

From source file:com.openerp.base.ir.Attachment.java

public void requestAttachment(Types type) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    switch (type) {
    case IMAGE_OR_CAPTURE_IMAGE:
        // createDialog(type);
        // break;
    case IMAGE://  www  .jav  a2  s . co  m
        intent.setType("image/*");
        requestIntent(intent, REQUEST_IMAGE);
        break;
    case CAPTURE_IMAGE:
        intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        requestIntent(intent, REQUEST_CAMERA);
        break;
    case AUDIO:
        intent.setType("audio/*");
        requestIntent(intent, REQUEST_AUDIO);
        break;
    case FILE:
        intent.setType("application/file");
        requestIntent(intent, REQUEST_FILE);
        break;
    default:
        break;
    }

}

From source file:com.albedinsky.android.support.intent.ImageIntent.java

/**
 * Creates a new instance of Intent with {@link Intent#ACTION_GET_CONTENT} and {@link MimeType#IMAGE}
 * MIME type that can be used to launch a gallery app (depends on user's choice) to pick one
 * of available images.//from ww  w  . jav  a 2  s .c o  m
 *
 * @return New gallery intent instance.
 */
@NonNull
public static Intent createGalleryIntent() {
    return new Intent(Intent.ACTION_GET_CONTENT).setType(MimeType.IMAGE);
}

From source file:com.mantz_it.rfanalyzer.SettingsFragment.java

@Override
public boolean onPreferenceClick(Preference preference) {
    // FileSource file:
    if (preference.getKey().equals(getString(R.string.pref_filesource_file))) {
        try {//  w  w w.j a v  a 2s .co  m
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("*/*");
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            startActivityForResult(Intent.createChooser(intent, "Select a file (8-bit complex IQ samples)"),
                    FILESOURCE_RESULT_CODE);

            // No error so far... let's dismiss the text input dialog:
            Dialog dialog = ((EditTextPreference) preference).getDialog();
            if (dialog != null)
                dialog.dismiss();
            return true;
        } catch (ActivityNotFoundException e) {
            Toast.makeText(SettingsFragment.this.getActivity(), "No file browser is installed!",
                    Toast.LENGTH_LONG).show();
            // Note that there is still the text dialog visible for the user to input a file path... so no more error handling necessary
        }
        return false;
    }
    // Show Log:
    else if (preference.getKey().equals(getString(R.string.pref_showLog))) {
        try {
            String logfile = ((EditTextPreference) findPreference(getString(R.string.pref_logfile))).getText();
            Uri uri = Uri.fromFile(new File(logfile));
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(uri, "text/plain");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            this.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            Toast.makeText(SettingsFragment.this.getActivity(), "No text viewer is installed!",
                    Toast.LENGTH_LONG).show();
        }
        return false;
    }
    return false;
}