Example usage for android.provider MediaStore ACTION_IMAGE_CAPTURE

List of usage examples for android.provider MediaStore ACTION_IMAGE_CAPTURE

Introduction

In this page you can find the example usage for android.provider MediaStore ACTION_IMAGE_CAPTURE.

Prototype

String ACTION_IMAGE_CAPTURE

To view the source code for android.provider MediaStore ACTION_IMAGE_CAPTURE.

Click Source Link

Document

Standard Intent action that can be sent to have the camera application capture an image and return it.

Usage

From source file:com.landenlabs.all_devtool.PackageFragment.java

/**
 * Load packages which are default (associated) with specific mime types.
 *
 * Use "adb shell dumpsys package r" to get full list
 *///w ww  .  j  a v  a  2s  . c o  m
void loadDefaultPackages() {
    m_workList = new ArrayList<PackingItem>();

    String[] actions = { Intent.ACTION_SEND, Intent.ACTION_SEND, Intent.ACTION_SEND, Intent.ACTION_SEND,

            Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW,
            Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW,

            MediaStore.ACTION_IMAGE_CAPTURE, MediaStore.ACTION_VIDEO_CAPTURE,

            Intent.ACTION_CREATE_SHORTCUT };

    String[] types = { "audio/*", "video/*", "image/*", "text/plain",

            "application/pdf", "application/zip", "audio/*", "video/*", "image/*", "text/html", "text/plain",
            "text/csv",

            "image/png", "video/*",

            "" };

    long orderCnt = 1;
    for (int idx = 0; idx != actions.length; idx++) {
        String type = types[idx];
        Intent resolveIntent = new Intent(actions[idx]);

        if (!TextUtils.isEmpty(type)) {
            if (type.startsWith("audio/*")) {
                Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
                resolveIntent.setDataAndType(uri, type);
            } else if (type.startsWith("video/*")) {
                Uri uri = Uri.withAppendedPath(MediaStore.Video.Media.INTERNAL_CONTENT_URI, "1");
                resolveIntent.setDataAndType(uri, type);
            } else if (type.startsWith("text/")) {
                Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath());
                resolveIntent.setDataAndType(uri, type);
            } else {
                resolveIntent.setType(type);
            }
        }

        PackageManager pm = getActivity().getPackageManager();

        // PackageManager.GET_RESOLVED_FILTER);  // or PackageManager.MATCH_DEFAULT_ONLY
        List<ResolveInfo> resolveList = pm.queryIntentActivities(resolveIntent, -1); // PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_INTENT_FILTERS);

        if (resolveList != null) {
            String actType = type = Utils.last(actions[idx].split("[.]")) + ":" + type;
            for (ResolveInfo resolveInfo : resolveList) {
                ArrayListPairString pkgList = new ArrayListPairString();
                String appName = resolveInfo.activityInfo.loadLabel(pm).toString().trim();

                addList(pkgList, "Type", actType);
                String pkgName = resolveInfo.activityInfo.packageName;
                PackageInfo packInfo = null;
                try {
                    packInfo = pm.getPackageInfo(pkgName, 0);
                    addList(pkgList, "Version", packInfo.versionName);
                    addList(pkgList, "VerCode", String.valueOf(packInfo.versionCode));
                    addList(pkgList, "TargetSDK", String.valueOf(packInfo.applicationInfo.targetSdkVersion));
                    m_date.setTime(packInfo.firstInstallTime);
                    addList(pkgList, "Install First", s_timeFormat.format(m_date));
                    m_date.setTime(packInfo.lastUpdateTime);
                    addList(pkgList, "Install Last", s_timeFormat.format(m_date));
                    if (resolveInfo.filter != null) {
                        if (resolveInfo.filter.countDataSchemes() > 0) {
                            addList(pkgList, "Intent Scheme", "");
                            for (int sIdx = 0; sIdx != resolveInfo.filter.countDataSchemes(); sIdx++)
                                addList(pkgList, " ", resolveInfo.filter.getDataScheme(sIdx));
                        }
                        if (resolveInfo.filter.countActions() > 0) {
                            addList(pkgList, "Intent Action", "");
                            for (int aIdx = 0; aIdx != resolveInfo.filter.countActions(); aIdx++)
                                addList(pkgList, " ", resolveInfo.filter.getAction(aIdx));
                        }
                        if (resolveInfo.filter.countCategories() > 0) {
                            addList(pkgList, "Intent Category", "");
                            for (int cIdx = 0; cIdx != resolveInfo.filter.countCategories(); cIdx++)
                                addList(pkgList, " ", resolveInfo.filter.getCategory(cIdx));
                        }
                        if (resolveInfo.filter.countDataTypes() > 0) {
                            addList(pkgList, "Intent DataType", "");
                            for (int dIdx = 0; dIdx != resolveInfo.filter.countDataTypes(); dIdx++)
                                addList(pkgList, " ", resolveInfo.filter.getDataType(dIdx));
                        }
                    }
                    m_workList.add(
                            new PackingItem(pkgName.trim(), pkgList, packInfo, orderCnt++, appName, actType));
                } catch (Exception ex) {
                }
            }
        }

        if (false) {
            // TODO - look into this method, see loadCachedPackages
            int flags = PackageManager.GET_PROVIDERS;
            List<PackageInfo> packList = pm.getPreferredPackages(flags);
            if (packList != null) {
                for (int pkgIdx = 0; pkgIdx < packList.size(); pkgIdx++) {
                    PackageInfo packInfo = packList.get(pkgIdx);

                    // if (((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) == showSys) {
                    addPackageInfo(packInfo);
                    // }
                }
            }
        }
    }

    // getPreferredAppInfo();

    /*
    List<ProviderInfo> providerList = getActivity().getPackageManager().queryContentProviders(null, 0, 0);
    if (providerList != null) {
    for (ProviderInfo providerInfo : providerList) {
        String name = providerInfo.name;
        String pkg = providerInfo.packageName;
            
    }
    }
    */
}

From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java

private boolean takePhoto() {
    final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (!getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
        return false;
    final File cache_dir = getExternalCacheDir();
    final File file = new File(cache_dir, "tmp_photo_" + System.currentTimeMillis());
    mTempPhotoUri = Uri.fromFile(file);/*  ww w  . ja  v  a 2s  .c o m*/
    intent.putExtra(MediaStore.EXTRA_OUTPUT, mTempPhotoUri);
    try {
        startActivityForResult(intent, REQUEST_TAKE_PHOTO);
    } catch (final ActivityNotFoundException e) {
        showErrorMessage(this, null, e, false);
        return false;
    }
    return true;
}

From source file:nu.yona.app.ui.YonaActivity.java

private void pickCamera() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    skipVerification = true;
    startActivityForResult(intent, PICK_CAMERA);
}

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

void dispatchTakePictureIntentOrShowPicture() {

    ReadingListDetail detail = CommonPlace.currentReadingListDetails.get(mPager.getCurrentItem());
    if (detail.PicturePath == null || detail.PicturePath.equals("")) {

        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // Ensure that there's a camera activity to handle the intent
        if (takePictureIntent.resolveActivity(this.getPackageManager()) != null) {
            // Create the File where the photo should go
            File photoFile = null;
            try {
                photoFile = createImageFile();
            } catch (IOException ex) {
                ex.toString();//w  ww. j a va2 s  .  c om
                // Error occurred while creating the File
            }
            // Continue only if the File was successfully created
            if (photoFile != null) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
            }
        }
    } else {
        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_VIEW);
        //intent.setDataAndType(Uri.fromFile(file), "image/*");
        intent.setDataAndType(Uri.fromFile(new File(detail.PicturePath)), "image/*");
        startActivity(intent);
    }
}

From source file:com.chaqianma.jd.fragment.CompanyInfoFragment.java

@Override
public void onTakePhoto() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(Constants.TEMPPATH);
    if (!file.getParentFile().exists() && !file.mkdirs()) {

    } else {/*from   w w  w.j a v a2  s  . c o m*/
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
        startActivityForResult(intent, REQUEST_TAKE_PHOTO);
    }
}

From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java

private void takeBannerPhoto() {
    final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        final File cache_dir = Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO
                ? GetExternalCacheDirAccessor.getExternalCacheDir(getActivity())
                : new File(getExternalStorageDirectory().getPath() + "/Android/data/"
                        + getActivity().getPackageName() + "/cache/");
        final File file = new File(cache_dir, "tmp_photo_" + System.currentTimeMillis() + ".jpg");
        mImageUri = Uri.fromFile(file);//from ww w. java2 s. c  o  m
        intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageUri);
        startActivityForResult(intent, REQUEST_BANNER_TAKE_PHOTO);
    }
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static Intent createTakePhotoIntent(final Uri uri) {
    final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    return intent;
}

From source file:com.fvd.nimbus.PaintActivity.java

public void getPhoto() {
    try {/*ww  w.ja  va 2s  . co  m*/
        showProgress(true);
        photoFileName = String.valueOf(System.currentTimeMillis()) + "-tmp.jpg";
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File file = new File(appSettings.getInstance().SavingPath, photoFileName);
        outputFileUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(intent, TAKE_PHOTO);
        //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
        overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
    } catch (Exception e) {
        appSettings.appendLog("main:getPhoto  " + e.getMessage());
        showProgress(false);
    }
}

From source file:it.feio.android.omninotes.DetailFragment.java

private void takePhoto() {
    // Checks for camera app available
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (!IntentChecker.isAvailable(mainActivity, intent, new String[] { PackageManager.FEATURE_CAMERA })) {
        mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.ALERT);

        return;/*from w w w  .j a v a2s .c om*/
    }
    // Checks for created file validity
    File f = StorageHelper.createNewAttachmentFile(mainActivity, Constants.MIME_TYPE_IMAGE_EXT);
    if (f == null) {
        mainActivity.showMessage(R.string.error, ONStyle.ALERT);
        return;
    }
    // Launches intent
    attachmentUri = Uri.fromFile(f);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri);
    startActivityForResult(intent, TAKE_PHOTO);
}

From source file:com.dycody.android.idealnote.DetailFragment.java

private void takePhoto() {
    // Checks for camera app available
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (!IntentChecker.isAvailable(mainActivity, intent, new String[] { PackageManager.FEATURE_CAMERA })) {
        //mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.ALERT);
        Toast.makeText(getActivity(), R.string.feature_not_available_on_this_device, Toast.LENGTH_SHORT).show();

        return;/*from  www. j av a2 s .c o m*/
    }
    // Checks for created file validity
    File f = StorageHelper.createNewAttachmentFile(mainActivity, Constants.MIME_TYPE_IMAGE_EXT);
    if (f == null) {
        Toast.makeText(getActivity(), R.string.error, Toast.LENGTH_SHORT).show();
        //mainActivity.showMessage(R.string.error, ONStyle.ALERT);
        return;
    }
    // Launches intent
    attachmentUri = Uri.fromFile(f);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri);
    startActivityForResult(intent, TAKE_PHOTO);
}