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


Java FileProvider类代码示例

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


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

示例1: installApk

import android.support.v4.content.FileProvider; //导入依赖的package包/类
private void installApk() {
    File[] files = mRxDownload.getRealFiles(mData.downloadUrl);
    if (files != null) {
        Uri uri = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uri = FileProvider.getUriForFile(mContext, mContext.getApplicationInfo().packageName + ".provider", files[0]);
        } else {
            uri = Uri.fromFile(files[0]);
        }
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setDataAndType(uri, "application/vnd.android.package-archive");
        mContext.startActivity(intent);
    } else {
        Toast.makeText(mContext, "File not exists", Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:AppInfoViewHolder.java

示例2: onContextItemSelected

import android.support.v4.content.FileProvider; //导入依赖的package包/类
@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case TAKE_PHOTO:
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File f = new File(Environment.getExternalStorageDirectory() + TMP_METACOM_JPG);
            Uri uri = FileProvider.getUriForFile(getContext(), AUTHORITY_STRING, f);
            takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
            takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                startActivityForResult(takePictureIntent, PICK_IMAGE_FROM_CAMERA);
            }
            return true;
        case FILE_EXPLORER:
            Intent intent = new Intent();
            intent.setType("*/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, getString(R.string
                            .select_file)),
                    PICK_IMAGE_FROM_EXPLORER);
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
 
开发者ID:metarhia,项目名称:metacom-android,代码行数:26,代码来源:ChatFragment.java

示例3: install

import android.support.v4.content.FileProvider; //导入依赖的package包/类
/**
 * 通过隐式意图调用系统安装程序安装APK
 */
public static void install(Context context) {
    File file = new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
            , apkname);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    // 由于没有在Activity环境下启动Activity,设置下面的标签
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (Build.VERSION.SDK_INT >= 24) { //判读版本是否在7.0以上
        //参数1 上下文, 参数2 Provider主机地址 和配置文件中保持一致   参数3  共享的文件
        Uri apkUri =
                FileProvider.getUriForFile(context, "com.hzecool.slhStaff.fileprovider", file);
        //添加这一句表示对目标应用临时授权该Uri所代表的文件
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
    } else {
        intent.setDataAndType(Uri.fromFile(file),
                "application/vnd.android.package-archive");
    }
    context.startActivity(intent);
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:24,代码来源:DownloadService.java

示例4: takeAPhoto

import android.support.v4.content.FileProvider; //导入依赖的package包/类
@NeedsPermission({Manifest.permission.CAMERA})
void takeAPhoto() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(this.getPackageManager()) != null) {
        Observable.just(this)
                .observeOn(Schedulers.newThread())
                .map((ctx) -> presenter.createImageFile(this))
                .subscribe(photoFile -> {
                    Timber.d(Thread.currentThread().getName());
                    if (photoFile != null) {
                        Uri photoURI = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID
                                + ".provider", presenter.createImageFile(this));
                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                        startActivityForResult(takePictureIntent, TAKE_PHOTO);
                    }
                }, t -> onLocationError());
    }
}
 
开发者ID:BANKEX,项目名称:smart-asset-iot-android-demo,代码行数:19,代码来源:MainActivity.java

示例5: openFile

import android.support.v4.content.FileProvider; //导入依赖的package包/类
private static void openFile(Activity activity, File file, String string, View view) {

        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(activity, activity.getApplicationContext().getPackageName() + ".provider", file);
            intent.setDataAndType(contentUri,string);

        } else {
            intent.setDataAndType(Uri.fromFile(file),string);
        }

        try {
            activity.startActivity (intent);
        } catch (ActivityNotFoundException e) {
            Snackbar.make(view, R.string.toast_install_app, Snackbar.LENGTH_LONG).show();
        }
    }
 
开发者ID:JaeNuguid,项目名称:Kids-Portal-Android,代码行数:22,代码来源:helper_main.java

示例6: 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

示例7: takePicture

import android.support.v4.content.FileProvider; //导入依赖的package包/类
public void takePicture() {
    try {
        mPhotoPath = sdcardPath + "/icon.jpg";
        mPhotoFile = new File(mPhotoPath);
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        if (Build.VERSION.SDK_INT >= 23) {
            Uri uri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", mPhotoFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

        } else {

            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mPhotoFile));
        }
        startActivityForResult(intent, 1);

    } catch (Exception e) {
    }



}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:23,代码来源:MyInfoActivity.java

示例8: installApk

import android.support.v4.content.FileProvider; //导入依赖的package包/类
private void installApk() {
    File[] files = mRxDownload.getRealFiles(data.record.getUrl());
    if (files != null) {
        Uri uri = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uri = FileProvider.getUriForFile(mContext, mContext.getApplicationInfo().packageName + ".provider", files[0]);
        } else {
            uri = Uri.fromFile(files[0]);
        }
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setDataAndType(uri, "application/vnd.android.package-archive");
        mContext.startActivity(intent);
    } else {
        Toast.makeText(mContext, "File not exists", Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:DownloadViewHolder.java

示例9: installApk

import android.support.v4.content.FileProvider; //导入依赖的package包/类
private void installApk() {
	File[] files = mRxDownload.getRealFiles(url);
	if (files != null) {
		Uri uri = null;
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
			uri = FileProvider.getUriForFile(this, getApplicationInfo().packageName + ".provider", files[0]);
		} else {
			uri = Uri.fromFile(files[0]);
		}
		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.setDataAndType(uri, "application/vnd.android.package-archive");
		startActivity(intent);
	} else {
		Toast.makeText(this, "File not exists", Toast.LENGTH_SHORT).show();
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:ServiceDownloadActivity.java

示例10: newCrop

import android.support.v4.content.FileProvider; //导入依赖的package包/类
public void newCrop() {
  File file = new File(Environment.getExternalStorageDirectory(),
      "/temp/" + System.currentTimeMillis() + ".jpg");
  if (!file.getParentFile().exists()) file.getParentFile().mkdirs();
  //输出路径只能用Uri.fromFile,不然报错
  //outputUri = FileProvider.getUriForFile(this, "com.liuguoquan.module.ui.provider",file);
  outputUri = Uri.fromFile(file);
  Uri imageUri = FileProvider.getUriForFile(getActivity(), "com.michael.materialdesign.provider",
      new File("/storage/emulated/0/temp/1476865100115.jpg"));//通过FileProvider创建一个content类型的Uri
  //grantUriPermission(getPackageName(),imageUri,Intent.FLAG_GRANT_READ_URI_PERMISSION);
  Intent intent = new Intent("com.android.camera.action.CROP");
  intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  intent.setDataAndType(mImageUri, "image/*");
  intent.putExtra("crop", "true");
  intent.putExtra("aspectX", 1);
  intent.putExtra("aspectY", 1);
  intent.putExtra("scale", true);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);
  intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
  intent.putExtra("noFaceDetection", true); // no face detection
  startActivityForResult(intent, 1008);
}
 
开发者ID:liuguoquan727,项目名称:android-study,代码行数:23,代码来源:Android7UI.java

示例11: shareImage

import android.support.v4.content.FileProvider; //导入依赖的package包/类
/**
 * Helper method for sharing an image.
 *
 * @param context   The image context.
 * @param imagePath The path of the image to be shared.
 */
static void shareImage(Context context, String imagePath) {
    // Create the share intent and start the share activity
    File imageFile = new File(imagePath);
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    //type determines the type of application an intent would choose
    shareIntent.setType("image/*");
    //To share a file with another app using a content URI, your app has to generate
    // the content URI. To generate the content URI, create a new File for the file,
    // then pass the File to getUriForFile(). You can send the content URI returned by
    // getUriForFile() to another app in an Intent. The client app that receives the content
    // URI can open the file and access its contents by calling
    // ContentResolver.openFileDescriptor to get a ParcelFileDescriptor.
    Uri photoURI = FileProvider.getUriForFile(context, FILE_PROVIDER_AUTHORITY, imageFile);
    shareIntent.putExtra(Intent.EXTRA_STREAM, photoURI);
    context.startActivity(shareIntent);
}
 
开发者ID:Masquerade0097,项目名称:Face_Animate,代码行数:23,代码来源:BitmapUtils.java

示例12: installUpdate

import android.support.v4.content.FileProvider; //导入依赖的package包/类
/**Installs the update by invoking the default packet installer*/
private void installUpdate(File downloadPath) {
    File apk = new File(downloadPath, ChromiumUpdater.CHROMIUM_SWE_APK);
    Intent intent = new Intent(Intent.ACTION_VIEW);

    Uri uri;
    if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        uri = FileProvider.getUriForFile(context, context.getApplicationContext()
                .getPackageName() + ".provider", apk);
        context.grantUriPermission("com.android.packageinstaller", uri,
                Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        context.grantUriPermission("com.google.android.packageinstaller", uri,
                Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } else {
        uri = Uri.fromFile(apk);
    }

    intent.setDataAndType(uri, "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
 
开发者ID:bamless,项目名称:chromium-swe-updater,代码行数:22,代码来源:ChromiumUpdater.java

示例13: dispatchTakePictureIntentTest4

import android.support.v4.content.FileProvider; //导入依赖的package包/类
private void dispatchTakePictureIntentTest4() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile(false);
        } catch (IOException ex) {
            // Error occurred while creating the File
            ex.printStackTrace();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                    "com.ge.droid.takingphotossimply.fileprovider",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PICTURE_TEST_4);
        }
    }
}
 
开发者ID:gejiaheng,项目名称:TakingPhotosSimply,代码行数:23,代码来源:MainActivity.java

示例14: takePicture

import android.support.v4.content.FileProvider; //导入依赖的package包/类
public void takePicture() {
    try {
        mPhotoPath = sdcardPath + "/icon.png";
        mPhotoFile = new File(mPhotoPath);
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        if (Build.VERSION.SDK_INT >= 23) {
            Uri uri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", mPhotoFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

        } else {

            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mPhotoFile));
        }
        startActivityForResult(intent, 1);
    } catch (Exception e) {
    }
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:19,代码来源:ReleaseDynActivity.java

示例15: installApk

import android.support.v4.content.FileProvider; //导入依赖的package包/类
private void installApk(Context context, String apkPath) {
    if (context == null || TextUtils.isEmpty(apkPath)) {
        return;
    }
    File file = new File(apkPath);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    //判读版本是否在7.0以上
    if (Build.VERSION.SDK_INT >= 24) {
        Uri apkUri = FileProvider.getUriForFile(context, context.getPackageName() + ".AgentWebFileProvider", file);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
    } else {
        intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    }
    context.startActivity(intent);
}
 
开发者ID:AriesHoo,项目名称:FastLib,代码行数:17,代码来源:WebViewActivity.java


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