當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。