当前位置: 首页>>代码示例>>Java>>正文


Java FileProvider.getUriForFile方法代码示例

本文整理汇总了Java中android.support.v4.content.FileProvider.getUriForFile方法的典型用法代码示例。如果您正苦于以下问题:Java FileProvider.getUriForFile方法的具体用法?Java FileProvider.getUriForFile怎么用?Java FileProvider.getUriForFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.content.FileProvider的用法示例。


在下文中一共展示了FileProvider.getUriForFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: callCamera

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
private void callCamera() {

        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = timeStamp + ".jpg";
        File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        pictureImagePath = storageDir.getAbsolutePath() + "/" + imageFileName;

        File file = new File(pictureImagePath);

        Uri outputFileUri = FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getApplicationContext().getPackageName() + ".provider", file);

        Intent CameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        CameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        CameraIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
        CameraIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        
        startActivityForResult(CameraIntent, 5);
    }
 
开发者ID:codingdojoangola,项目名称:cda-app,代码行数:19,代码来源:ChatActivity.java

示例2: openCameraWithOutput

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
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,代码行数:27,代码来源:ImageActivity.java

示例3: getInstallAppIntent

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
/**
 * 获取安装App(支持6.0)的意图
 *
 * @param file 文件
 * @return intent
 */
public static Intent getInstallAppIntent(File file) {
    if (file == null) return null;
    Intent intent = new Intent(Intent.ACTION_VIEW);
    String type;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        type = "application/vnd.android.package-archive";
    } else {
        type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(FileUtils.getFileExtension(file));
    }
    Uri uri;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        uri = FileProvider.getUriForFile(Utils.getContext(), AppUtils.getAppPackageName(Utils.getContext()), file);
    } else {
        uri = Uri.fromFile(file);
    }
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.setDataAndType(uri, type);
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:26,代码来源:IntentUtils.java

示例4: sendCameraIntent

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
private void sendCameraIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        File photo = null;
        try {
            photo = createImageFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if(photo != null){
            Uri file  = FileProvider.getUriForFile(this, "ir.hphamid.instagram.fileProvider", photo);
            imageUri = Uri.fromFile(photo);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, file);
            startActivityForResult(takePictureIntent, IMAGE_CAPTURE);
        }
    }
}
 
开发者ID:hphamid,项目名称:maktabkhoone-instagram,代码行数:18,代码来源:ShareImageActivity.java

示例5: do_add_video

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
@OnClick(R.id.fab_add_video)
public void do_add_video()
{
    Intent capture = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    if (capture.resolveActivity(getPackageManager()) != null) {
        try {
            File videoFile = createFileName("traxyvid", ".mp4");
            mediaUri = FileProvider.getUriForFile(this,
                    getPackageName() + ".provider", videoFile);
            capture.putExtra(MediaStore.EXTRA_OUTPUT, mediaUri);
            startActivityForResult(capture, CAPTURE_VIDEO_REQUEST);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:17,代码来源:JournalViewActivity.java

示例6: dispatchTakePictureIntent

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
private void dispatchTakePictureIntent() throws IOException {

        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            // Create the File where the photo should go
            File photoFile = null;
            try {
                photoFile = createImageFile();
            } catch (IOException ex) {
                // Error occurred while creating the File
            }
            // Continue only if the File was successfully created
            if (photoFile != null) {
                Uri photoURI = FileProvider.getUriForFile(this,
                        "com.naren.quire.provider",
                        photoFile);
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
            }
        }
    }
 
开发者ID:narenkukreja,项目名称:quire,代码行数:23,代码来源:ListNewItemActivity.java

示例7: shareScreenshot

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
private void shareScreenshot() {
    Bitmap bitmap = BitmapUtils.getBitmapFromView(binding.constraint);
    File dir = getFilesDir();
    File file = new File(dir, "font-screenshot.png");
    try {
        FileOutputStream outputStream = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
        outputStream.close();
    } catch (IOException e) {
        Log.e(TAG, "Failed to save screenshot");
        Snackbar.make(binding.coord, R.string.failed_to_save_screenshot, Snackbar.LENGTH_SHORT).show();
        return;
    }

    Uri uri = FileProvider.getUriForFile(TypesetterActivity.this,
            "com.bignerdranch.android.typesetter.fileprovider",
            file);
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/png");
    intent.putExtra(Intent.EXTRA_STREAM, uri);

    startActivity(intent);
}
 
开发者ID:bignerdranch,项目名称:Typesetter,代码行数:24,代码来源:TypesetterActivity.java

示例8: dispatchTakePictureIntent

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
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,代码行数:22,代码来源:ImageCaptureManager.java

示例9: getInstallAppIntent

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
/**
 * 获取安装App(支持6.0)的意图
 *
 * @param file 文件
 * @return intent
 */
public static Intent getInstallAppIntent(File file)
{
    if(file == null) return null;
    Intent intent = new Intent(Intent.ACTION_VIEW);
    String type;

    if(Build.VERSION.SDK_INT < 23)
    {
        type = "application/vnd.android.package-archive";
    }
    else
    {
        type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(FileTool.getExtension(file));
    }

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
    {
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Uri contentUri = FileProvider
                .getUriForFile(Easy.getContext(), "com.your.package.fileProvider", file);
        intent.setDataAndType(contentUri, type);
    }
    intent.setDataAndType(Uri.fromFile(file), type);
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
 
开发者ID:Ayvytr,项目名称:EasyAndroid,代码行数:32,代码来源:IntentTool.java

示例10: callCamera

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
private void callCamera() {
    ContentValues values = new ContentValues();
    File imagePath = new File(getFilesDir(), "covers");
    if(!imagePath.exists()) imagePath.mkdir();
    File newFile = new File(imagePath, System.currentTimeMillis() + "photo.png");

    if (Build.VERSION.SDK_INT > 21) { //use this if Lollipop_Mr1 (API 22) or above
        mPicturePath = FileProvider.getUriForFile(this, getPackageName()+".fileprovider", newFile);
    } else {
        mPicturePath = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    }

    Intent it = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    it.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    it.putExtra(MediaStore.EXTRA_OUTPUT, mPicturePath);
    startActivityForResult(it, RC_CAMERA);
}
 
开发者ID:victoraldir,项目名称:BuddyBook,代码行数:18,代码来源:InsertEditBookActivity.java

示例11: takePicture

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
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,代码行数:34,代码来源:CameraLauncher.java

示例12: shareBitmapToOtherApp

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
public void shareBitmapToOtherApp(Bitmap bitmap, Activity activity) {
    File file = new File(getCacheDir(), getString(R.string.cached_picture_filename));
    File imageFile = ContextUtils.get().writeImageToFileJpeg(file, bitmap);
    if (imageFile != null) {
        Uri imageUri = FileProvider.getUriForFile(this, getString(R.string.app_fileprovider), imageFile);
        if (imageUri != null) {
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            shareIntent.setDataAndType(imageUri, getContentResolver().getType(imageUri));
            shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
            activity.startActivity(Intent.createChooser(shareIntent, getString(R.string.main__share_meme_prompt)));
        }
    }
}
 
开发者ID:gsantner,项目名称:memetastic,代码行数:16,代码来源:App.java

示例13: openCamera

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
private void openCamera() {
    tmpFile = new File(getCacheDir(), System.currentTimeMillis() + ".jpg");
    Uri upload_temp_uri = FileProvider.getUriForFile(this, getString(R.string.authProvider), tmpFile);
    Intent mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    mIntent.putExtra(MediaStore.EXTRA_OUTPUT, upload_temp_uri);
    startActivityForResult(mIntent, Camera);
}
 
开发者ID:RanKKI,项目名称:PSNine,代码行数:8,代码来源:ImagesGalleryActivity.java

示例14: getInstallAppIntent

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
/**
 * 获取安装App(支持7.0)的意图
 *
 * @param file      文件
 * @param authority 7.0及以上安装需要传入清单文件中的{@code <provider>}的authorities属性
 *                  <br>参看https://developer.android.com/reference/android/support/v4/content/FileProvider.html
 * @return intent
 */
public static Intent getInstallAppIntent(File file, String authority) {
    if (file == null) return null;
    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri data;
    String type = "application/vnd.android.package-archive";
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        data = Uri.fromFile(file);
    } else {
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        data = FileProvider.getUriForFile(Utils.getContext(), authority, file);
    }
    intent.setDataAndType(data, type);
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
 
开发者ID:penghongru,项目名称:Coder,代码行数:23,代码来源:IntentUtils.java

示例15: changePhotoActionSelected

import android.support.v4.content.FileProvider; //导入方法依赖的package包/类
private void changePhotoActionSelected(int position) {
    if (position == 0) { //take photo
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
            File newFile = mPresenter.getTempImageFileForOwner();
            Uri uri = FileProvider.getUriForFile(getActivity(), getString(R.string.file_provider), newFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

            List<ResolveInfo> cameraActivities = getActivity().getPackageManager()
                    .queryIntentActivities(takePictureIntent, PackageManager.MATCH_DEFAULT_ONLY);
            for (ResolveInfo activity : cameraActivities) {
                getActivity().grantUriPermission(
                        activity.activityInfo.packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            }

            startActivityForResult(takePictureIntent, Constants.RESULT_PROFILE_IMAGE_TAKEN);
        }
    } else if (position == 1) { //select photo
        Intent imageIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        imageIntent.setType("image/*");
        imageIntent.putExtra("return-data", true);
        imageIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
        startActivityForResult(
                Intent.createChooser(imageIntent, getString(R.string.select_photo)),
                Constants.RESULT_PROFILE_IMAGE_SELECTED);
    }
}
 
开发者ID:Q115,项目名称:Goalie_Android,代码行数:28,代码来源:ProfileFragment.java


注:本文中的android.support.v4.content.FileProvider.getUriForFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。