當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaStore.ACTION_IMAGE_CAPTURE屬性代碼示例

本文整理匯總了Java中android.provider.MediaStore.ACTION_IMAGE_CAPTURE屬性的典型用法代碼示例。如果您正苦於以下問題:Java MediaStore.ACTION_IMAGE_CAPTURE屬性的具體用法?Java MediaStore.ACTION_IMAGE_CAPTURE怎麽用?Java MediaStore.ACTION_IMAGE_CAPTURE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.provider.MediaStore的用法示例。


在下文中一共展示了MediaStore.ACTION_IMAGE_CAPTURE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: openCamera

/**
 * 打開係統相機
 * @param context
 * @param fileName
 */
public static void openCamera(Context context, String fileName) {
    String status = Environment.getExternalStorageState();
    if (!Environment.MEDIA_MOUNTED.equals(status)) {
        Toast.makeText(context, "SD卡不可以", Toast.LENGTH_LONG).show();
        return;
    }
    File mCurrentPhotoFile = new File(context.getExternalCacheDir(), fileName);
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    Uri imageUri;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // 7.0使用FileProvider
        imageUri = FileProvider.getUriForFile(context, "com.highway.study.provider", mCurrentPhotoFile);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } else {
        imageUri = Uri.fromFile(mCurrentPhotoFile);
    }
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, MAX_PHOTO_SIZE);
    ((Activity)context).startActivityForResult(intent, CAMERA_WITH_DATA);
}
 
開發者ID:wuhighway,項目名稱:DailyStudy,代碼行數:24,代碼來源:PhotoUtils.java

示例2: requestSysCamera

/**
 * Fragment調用係統拍照
 *
 * @param fragment
 * @param requestCode
 */
public void requestSysCamera(android.support.v4.app.Fragment fragment, int requestCode) {
    requestCamaraPath = getPhotoTmpPath();
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(requestCamaraPath)));
    fragment.startActivityForResult(intent, requestCode);
}
 
開發者ID:quickhybrid,項目名稱:quickhybrid-android,代碼行數:13,代碼來源:PhotoSelector.java

示例3: onLongClick

@Override
public boolean onLongClick(View arg0) {
    // 

    if (mSettings.getBoolean("use_as_lock_main", false)) {
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    }
    Intent i = new Intent(
            MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager pm = getPackageManager();

    final ResolveInfo mInfo = pm.resolveActivity(i, 0);

    Intent intent = new Intent();
    intent.setComponent(new ComponentName(
            mInfo.activityInfo.packageName, mInfo.activityInfo.name));
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    startActivity(intent);
    return true;
}
 
開發者ID:89luca89,項目名稱:ThunderMusic,代碼行數:23,代碼來源:MediaLockscreenActivity.java

示例4: dispatchTakePictureIntent

public Intent dispatchTakePictureIntent() throws IOException {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(mContext.getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = createImageFile();

        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri uri = null;
            if (Build.VERSION.SDK_INT >= 24) {
                uri = FileProvider.getUriForFile(mContext.getApplicationContext(), mContext.getPackageName() + ".file_provider", photoFile);
            } else {
                uri = Uri.fromFile(photoFile);
            }
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            takePictureIntent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);//增加讀寫權限
        }
    }
    return takePictureIntent;
}
 
開發者ID:Sugarya,項目名稱:SugarPhotoPicker,代碼行數:21,代碼來源:ImageCaptureManager.java

示例5: dispatchCaptureIntent

public void dispatchCaptureIntent(Context context, int requestCode) {
    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (captureIntent.resolveActivity(context.getPackageManager()) != null) {
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (photoFile != null) {
            mCurrentPhotoPath = photoFile.getAbsolutePath();
            mCurrentPhotoUri = FileProvider.getUriForFile(mContext.get(),
                    mCaptureStrategy.authority, photoFile);
            captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCurrentPhotoUri);
            captureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                List<ResolveInfo> resInfoList = context.getPackageManager()
                        .queryIntentActivities(captureIntent, PackageManager.MATCH_DEFAULT_ONLY);
                for (ResolveInfo resolveInfo : resInfoList) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    context.grantUriPermission(packageName, mCurrentPhotoUri,
                            Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
            }
            if (mFragment != null) {
                mFragment.get().startActivityForResult(captureIntent, requestCode);
            } else {
                mContext.get().startActivityForResult(captureIntent, requestCode);
            }
        }
    }
}
 
開發者ID:sathishmscict,項目名稱:Matisse-Image-and-Video-Selector,代碼行數:33,代碼來源:MediaStoreCompat.java

示例6: do_add_photo

@OnClick(R.id.fab_add_photo)
public void do_add_photo()
{
    Intent capture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (capture.resolveActivity(getPackageManager()) != null) {
        try {
            File photoFile = createFileName("traxypic", ".jpg");
            mediaUri = FileProvider.getUriForFile(this,
                    getPackageName() + ".provider", photoFile);
            capture.putExtra(MediaStore.EXTRA_OUTPUT, mediaUri);
            startActivityForResult(capture, CAPTURE_PHOTO_REQUEST);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
開發者ID:gvsucis,項目名稱:mobile-app-dev-book,代碼行數:16,代碼來源:JournalViewActivity.java

示例7: openCameraWithOutput

private void openCameraWithOutput() {
    String path = new File(Environment.getExternalStorageDirectory(), "ktools").getAbsolutePath();
    if (!new File(path).exists()) {
        new File(path).mkdirs();
    }
    outputImageFile = new File(path, System.currentTimeMillis() + ".png");
    if (!outputImageFile.exists()) {
        try {
            outputImageFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //兼容7.0
    Uri contentUri = FileProvider.getUriForFile(
            this,
            BuildConfig.APPLICATION_ID,
            outputImageFile
    );
    Log.d(TAG, "openCameraWithOutput: uri = " + contentUri.toString());
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(Intent.EXTRA_MIME_TYPES, MimeTypeMap.getSingleton().getMimeTypeFromExtension("png"));
    //指定輸出路徑
    intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
    startActivityForResult(intent, REQUEST_CODE_CAPTURE_IMAGE_WITHOUT_COMPRESS);
}
 
開發者ID:jiangkang,項目名稱:KTools,代碼行數:26,代碼來源:ImageActivity.java

示例8: onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (cameraResultListener != null && cameraResultListener.getFilePath() != null) {
        File tempImageFile = new File(cameraResultListener.getFilePath());
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        Uri uri = PSFileProvider.getUriForFile(this, PSFileProvider.getProviderName(this), tempImageFile);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        this.startActivityForResult(intent, REQUEST_CODE);
    } else {
        Intent result = new Intent();
        setResult(Activity.RESULT_CANCELED, result);
        finish();
    }
}
 
開發者ID:PrivacyStreams,項目名稱:PrivacyStreams,代碼行數:15,代碼來源:PSCameraActivity.java

示例9: takePicture

public void takePicture(int returnType, int encodingType)
    {
        // Save the number of images currently on disk for later
        this.numPics = queryImgDB(whichContentStore()).getCount();

        // Let's use the intent and see what happens
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        // Specify file so that large image is captured and returned
        File photo = createCaptureFile(encodingType);
        this.imageUri = new CordovaUri(FileProvider.getUriForFile(cordova.getActivity(),
                applicationId + ".provider",
                photo));
        intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri.getCorrectUri());
        //We can write to this URI, this will hopefully allow us to write files to get to the next step
        intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

        if (this.cordova != null) {
            // Let's check to make sure the camera is actually installed. (Legacy Nexus 7 code)
            PackageManager mPm = this.cordova.getActivity().getPackageManager();
            if(intent.resolveActivity(mPm) != null)
            {

                this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
            }
            else
            {
                LOG.d(LOG_TAG, "Error: You don't have a default camera.  Your device may not be CTS complaint.");
            }
        }
//        else
//            LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
    }
 
開發者ID:Andy-Ta,項目名稱:COB,代碼行數:33,代碼來源:CameraLauncher.java

示例10: startCamera

@Override
public void startCamera(@NonNull Uri fileUri) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
        startActivityForResult(takePictureIntent, REQUEST_PHOTO_FROM_CAMERA);
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:8,代碼來源:MessageAttachmentsFragment.java

示例11: openCamera

public static Uri openCamera(Activity activity) {

        if (isStoragePermissionGranted(activity,
                activity.getResources().getInteger(R.integer.camera_request))) {

            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

            Uri photoURI;

            ContentValues values = new ContentValues(1);
            values.put(MediaStore.Images.Media.MIME_TYPE, "profile_image/jpg");
            photoURI = activity.getContentResolver()
                    .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

            intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            intent.addFlags(
                    Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            if (photoURI != null) {
                intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
            }

            activity.startActivityForResult(intent,
                    activity.getResources().getInteger(R.integer.camera_request));

            return photoURI;
        }
        return null;
    }
 
開發者ID:sciage,項目名稱:FinalProject,代碼行數:29,代碼來源:ActivityUtils.java

示例12: openCameraImage

public static void openCameraImage(final Fragment fragment) {
    imageUriFromCamera = createImagePathUri(fragment.getContext());

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // MediaStore.EXTRA_OUTPUT參數不設置時,係統會自動生成一個uri,但是隻會返回一個縮略圖
    // 返回圖片在onActivityResult中通過以下代碼獲取
    // Bitmap bitmap = (Bitmap) data.getExtras().get("data");
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUriFromCamera);
    fragment.startActivityForResult(intent, GET_IMAGE_BY_CAMERA);
}
 
開發者ID:ChunweiDu,項目名稱:Utils,代碼行數:10,代碼來源:PhotoUtil.java

示例13: dispatchTakePictureIntent

@OnClick(R.id.button)
public void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }
}
 
開發者ID:micromasterandroid,項目名稱:androidadvanced,代碼行數:7,代碼來源:MainActivity.java

示例14: startCamera

public static void startCamera(Activity activity,BasePhotoBuilder builder){

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //添加這一句表示對目標應用臨時授權該Uri所代表的文件
        intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        Uri mDestinationUri = buildUri(builder,true);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, mDestinationUri);
        activity.startActivityForResult(intent, PhotoUtil.REQUEST_CAMERA);
    }
 
開發者ID:hss01248,項目名稱:PhotoOut,代碼行數:9,代碼來源:MyTool.java

示例15: choseHeadImageFromCameraCapture

/**
 * 從手機相機拍攝圖片設置用戶頭像
 */
private void choseHeadImageFromCameraCapture() {
    Intent intentFromCapture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    //判斷存儲卡是否可用,存儲照片文件
    if(hasSdcard()){
        intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File(Environment.getExternalStorageDirectory(),IMAGE_FILE_NAME)));
        }
    startActivityForResult(intentFromCapture,CODE_CAMERA_REQUEST);
}
 
開發者ID:AndroidBoySC,項目名稱:Mybilibili,代碼行數:11,代碼來源:MainActivity.java


注:本文中的android.provider.MediaStore.ACTION_IMAGE_CAPTURE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。