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:net.ustyugov.jtalk.activity.vcard.SetVcardActivity.java

@Override
public void onClick(View v) {
    if (v.equals(clear)) {
        bytes = null;/*from   w w  w .j  av  a 2  s  .c  o m*/
        av.setImageBitmap(null);
    } else if (v.equals(load)) {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
        startActivityForResult(Intent.createChooser(intent, null), IMAGE);
    }
}

From source file:ca.ualberta.cmput301w14t08.geochan.fragments.PostFragment.java

/**
 * Displays dialog and either launches camera or gallery
 * //w ww. j  ava2 s  .  com
 * @param view
 *            the AttachPhoto button in postThreadFragment.
 */
public void attachImage(View view) {
    if (view.getId() == R.id.attach_image_button) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
        dialog.setTitle(R.string.attach_image_title);
        dialog.setMessage(R.string.attach_image_dialog);
        dialog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                FavouritesFragment favFrag = (FavouritesFragment) getParentFragment();
                boolean fromFav;
                if (favFrag != null) {
                    fromFav = true;
                } else {
                    fromFav = false;
                }
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                if (fromFav == true) {
                    arg0.dismiss();
                    getParentFragment().startActivityForResult(Intent.createChooser(intent, "Test"),
                            ImageHelper.REQUEST_GALLERY);
                } else {
                    arg0.dismiss();
                    startActivityForResult(Intent.createChooser(intent, "Test"), ImageHelper.REQUEST_GALLERY);
                }
            }
        });

        dialog.setNegativeButton("Camera", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                FavouritesFragment favFrag = (FavouritesFragment) getParentFragment();
                boolean fromFav;
                if (favFrag != null) {
                    fromFav = true;
                } else {
                    fromFav = false;
                }
                Intent intent = new Intent();
                intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                try {
                    imageFile = ImageHelper.createImageFile();
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
                    if (fromFav == true) {
                        arg0.dismiss();
                        getParentFragment().startActivityForResult(Intent.createChooser(intent, "Test"),
                                ImageHelper.REQUEST_CAMERA);
                    } else {
                        arg0.dismiss();
                        startActivityForResult(Intent.createChooser(intent, "Test"),
                                ImageHelper.REQUEST_CAMERA);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        dialog.show();
    }
}

From source file:de.treichels.hott.ui.android.MdlViewerActivity.java

/**
 * Fires an intent to spin up the "file chooser" UI and select a file. Response will be handled by {@link MdlViewerActivity.onActivityResult()}
 */// ww w .j  ava2 s .  co  m
public void performFileSearch() {
    Toast.makeText(getApplicationContext(), R.string.msg_select_mdl, Toast.LENGTH_SHORT).show();

    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(MDL_MIME_TYPE);

    startActivityForResult(intent, READ_REQUEST_CODE);
}

From source file:com.oxplot.contactphotosync.AssignContactPhotoActivity.java

@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    thumbSize = getResources().getInteger(R.integer.config_list_thumb_size);

    if (savedState != null) {
        String cropTempPath = savedState.getString("crop_temp");
        if (cropTempPath != null)
            cropTemp = new File(cropTempPath);
        pickedRawContact = savedState.getInt("picked_raw_contact", 0);
    }//from w w  w  .j a  va  2 s  . c  o m

    // Initialize cache directory

    new File(getCacheDir(), DISK_CACHE_DIR).mkdir();

    unchangedThumb = new BitmapDrawable(getResources(), Bitmap.createBitmap(1, 1, Config.ALPHA_8));

    setContentView(R.layout.activity_assign_contact_photo);
    contactList = (ListView) findViewById(R.id.contactList);
    emptyList = (TextView) findViewById(R.id.empty);
    loadingProgress = (ProgressBar) findViewById(R.id.loading);

    contactList.setEmptyView(loadingProgress);
    contactList.setAdapter(new ContactAdapter());
    contactList.setDividerHeight(1);
    contactList.setMultiChoiceModeListener(new ContactListMultiChoiceModeListener());
    contactList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    account = getIntent().getStringExtra("account");
    setTitle(account);

    thumbMemCache = new SparseArray<Drawable>();
    asyncTasks = new HashSet<AsyncTask<?, ?, ?>>();
    defaultThumb = getResources().getDrawable(R.drawable.new_picture);

    contactList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {

            pickedRawContact = ((Contact) contactList.getItemAtPosition(position)).rawContactId;
            Intent intent = new Intent();

            // We only really accept PNG and JPEG but the activities registered for
            // the intended action only accept the generic form of the mime type. We
            // will check for our constraints after the image is picked.

            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(
                    Intent.createChooser(intent, getResources().getString(R.string.select_picture)),
                    REQ_CODE_PICK_IMAGE);

        }
    });

}

From source file:com.core.base.js.UploadHandler.java

private Intent createDefaultOpenableIntent() {
    // Create and return a chooser with the default OPENABLE
    // actions including the camera, camcorder and sound
    // recorder where available.
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("*/*");

    Intent chooser = createChooserIntent();
    chooser.putExtra(Intent.EXTRA_INTENT, i);
    return chooser;
}

From source file:com.github.guwenk.smuradio.SignInDialog.java

private void showFileChooser() {
    Intent intent = new Intent();
    intent.setType("audio/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, getString(R.string.select_music)), PICK_MUSIC_REQUEST);
}

From source file:com.snappy.CameraCropActivity.java

private void getImageIntents() {
    /*/* w w w  .j av  a2s. c  o  m*/
     * if (getIntent().hasExtra("trio")) { _trio = true; _groupId =
     * getIntent().getStringExtra("groupId"); _planner =
     * getIntent().getBooleanExtra("planner", false); } else { _trio =
     * false; _planner = false; _groupId = ""; }
     */
    if (getIntent().getStringExtra("type").equals("gallery")) {

        //this is used to solve the selected path for android 19, kitkat o superior
        if (Build.VERSION.SDK_INT < 19) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            this.startActivityForResult(intent, GALLERY);
        } else {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("image/*");
            this.startActivityForResult(intent, GALLERY);
        }

        mIsCamera = false;

    } else {
        try {
            startCamera();
            mIsCamera = true;
        } catch (UnsupportedOperationException ex) {
            ex.printStackTrace();
            Toast.makeText(getBaseContext(), "UnsupportedOperationException", Toast.LENGTH_SHORT).show();
        }
    }
    if (getIntent().getBooleanExtra("profile", false) == true) {
        mForProfile = true;
    } else {
        mForProfile = false;
    }
    if (getIntent().getBooleanExtra("createGroup", false) == true) {
        mForGroup = true;
    } else {
        mForGroup = false;
    }
    if (getIntent().getBooleanExtra("groupUpdate", false) == true) {
        mForGroupUpdate = true;
    } else {
        mForGroupUpdate = false;
    }
}

From source file:com.intel.xdk.camera.Camera.java

private void pickImage() {
    if (busy) {/*from   w ww .  ja v a2  s  . c  om*/
        cameraBusy();
    }
    busy = true;
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    cordova.startActivityForResult(this, intent, SELECT_PICTURE);
}

From source file:com.MustacheMonitor.MustacheMonitor.StacheCam.java

/**
 * Get image from photo library./*from   www .j  a  v  a 2  s .  co  m*/
 *
 * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param srcType           The album to get image from.
 * @param returnType        Set the type of image to return.
 */
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
public void getImage(int srcType, int returnType) {
    Intent intent = new Intent();
    String title = GET_PICTURE;
    if (this.mediaType == PICTURE) {
        intent.setType("image/*");
    } else if (this.mediaType == VIDEO) {
        intent.setType("video/*");
        title = GET_VIDEO;
    } else if (this.mediaType == ALLMEDIA) {
        // I wanted to make the type 'image/*, video/*' but this does not work on all versions
        // of android so I had to go with the wildcard search.
        intent.setType("*/*");
        title = GET_All;
    }

    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    if (this.cordova != null) {
        this.cordova.startActivityForResult((Plugin) this, Intent.createChooser(intent, new String(title)),
                (srcType + 1) * 16 + returnType + 1);
    }
}

From source file:com.scoreflex.ScoreflexView.java

/**
 * The constructor of the view./* ww  w. j av  a2  s. c o  m*/
 * @param activity The activity holding the view.
 * @param attrs
 * @param defStyle
 */
@SuppressWarnings("deprecation")
public ScoreflexView(Activity activity, AttributeSet attrs, int defStyle) {
    super(activity, attrs, defStyle);

    // Keep a reference on the activity
    mParentActivity = activity;

    // Default layout params
    if (null == getLayoutParams()) {
        setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                Scoreflex.getDensityIndependantPixel(R.dimen.scoreflex_panel_height)));
    }

    // Set our background color
    setBackgroundColor(getContext().getResources().getColor(R.color.scoreflex_background_color));

    // Create the top bar
    View topBar = new View(getContext());
    topBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height), Gravity.TOP));
    topBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.scoreflex_gradient_background));
    addView(topBar);

    // Create the retry button
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mErrorLayout = (ViewGroup) inflater.inflate(R.layout.scoreflex_error_layout, null);
    if (mErrorLayout != null) {

        // Configure refresh button
        Button refreshButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_retry_button);
        if (null != refreshButton) {
            refreshButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    if (null == Scoreflex.getPlayerId()) {
                        setUserInterfaceState(new LoadingState());
                        loadUrlAfterLoggedIn(mInitialResource, mInitialRequestParams);
                    } else if (null == mWebView.getUrl()) {
                        setResource(mInitialResource);
                    } else {
                        mWebView.reload();
                    }
                }
            });
        }

        // Configure cancel button
        Button cancelButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_cancel_button);
        if (null != cancelButton) {
            cancelButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    close();
                }
            });
        }

        // Get hold of the message view
        mMessageView = (TextView) mErrorLayout.findViewById(R.id.scoreflex_error_message_view);
        addView(mErrorLayout);

    }

    // Create the close button
    mCloseButton = new ImageButton(getContext());
    Drawable closeButtonDrawable = getResources().getDrawable(R.drawable.scoreflex_close_button);
    int closeButtonMargin = (int) ((getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height)
            - closeButtonDrawable.getIntrinsicHeight()) / 2.0f);
    FrameLayout.LayoutParams closeButtonLayoutParams = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.TOP | Gravity.RIGHT);
    closeButtonLayoutParams.setMargins(0, closeButtonMargin, closeButtonMargin, 0);
    mCloseButton.setLayoutParams(closeButtonLayoutParams);
    mCloseButton.setImageDrawable(closeButtonDrawable);
    mCloseButton.setBackgroundDrawable(null);
    mCloseButton.setPadding(0, 0, 0, 0);
    mCloseButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            close();
        }
    });
    addView(mCloseButton);

    // Create the web view
    mWebView = new WebView(mParentActivity);
    mWebView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    // mWebView.setBackgroundColor(Color.RED);
    mWebView.setWebViewClient(new ScoreflexWebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient() {

        @Override
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.d("Scoreflex", "javascript Error: "
                    + String.format("%s @ %d: %s", cm.message(), cm.lineNumber(), cm.sourceId()));
            return true;
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            // mtbActivity.mUploadMessage = uploadMsg;
            mUploadMessage = uploadMsg;

            String fileName = "picture.jpg";
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.TITLE, fileName);
            // mOutputFileUri = mParentActivity.getContentResolver().insert(
            // MediaStore.Images.Media.DATA, values);
            final List<Intent> cameraIntents = new ArrayList<Intent>();
            final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            final PackageManager packageManager = mParentActivity.getPackageManager();
            final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
            for (ResolveInfo res : listCam) {
                final String packageName = res.activityInfo.packageName;
                final Intent intent = new Intent(captureIntent);
                intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
                intent.setPackage(packageName);
                cameraIntents.add(intent);
            }

            // Filesystem.
            final Intent galleryIntent = new Intent();
            galleryIntent.setType("image/*");
            galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

            // Chooser of filesystem options.
            final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source please");

            // Add the camera options.
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));

            mParentActivity.startActivityForResult(chooserIntent, Scoreflex.FILECHOOSER_RESULTCODE);
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
            openFileChooser(uploadMsg);
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
            openFileChooser(uploadMsg);
        }
    });
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.getSettings().setDatabasePath(
            getContext().getFilesDir().getPath() + "/data/" + getContext().getPackageName() + "/databases/");
    addView(mWebView);

    TypedArray a = mParentActivity.obtainStyledAttributes(attrs, R.styleable.ScoreflexView, defStyle, 0);
    String resource = a.getString(R.styleable.ScoreflexView_resource);
    if (null != resource)
        setResource(resource);

    a.recycle();

    // Create the animated spinner

    mProgressBar = (ProgressBar) ((LayoutInflater) getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.scoreflex_progress_bar, null);
    mProgressBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
    addView(mProgressBar);
    LocalBroadcastManager.getInstance(activity).registerReceiver(mLoginReceiver,
            new IntentFilter(Scoreflex.INTENT_USER_LOGED_IN));
    setUserInterfaceState(new InitialState());
}