项目:GitHub
文件:AppInfoViewHolder.java
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();
}
}
@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);
}
}
项目:smart-asset-iot-android-demo
文件:MainActivity.java
@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());
}
}
项目:Kids-Portal-Android
文件:helper_main.java
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();
}
}
项目:mobile-app-dev-book
文件:JournalViewActivity.java
@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();
}
}
}
项目:GCSApp
文件:MyInfoActivity.java
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) {
}
}
项目:GitHub
文件:DownloadViewHolder.java
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,Toast.LENGTH_SHORT).show();
}
}
项目:GitHub
文件:ServiceDownloadActivity.java
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","application/vnd.android.package-archive");
startActivity(intent);
} else {
Toast.makeText(this,Toast.LENGTH_SHORT).show();
}
}
项目:android-study
文件:Android7UI.java
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);
}
项目:Face_Animate
文件:BitmapUtils.java
/**
* 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);
}
项目:chromium-swe-updater
文件:ChromiumUpdater.java
/**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",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);
}
项目:TakingPhotosSimply
文件:MainActivity.java
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);
}
}
}
项目:GCSApp
文件:ReleaseDynActivity.java
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,1);
} catch (Exception e) {
}
}
项目:FastLib
文件:WebViewActivity.java
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);
}
项目:DaiGo
文件:DownloadService.java
/**
* 打开下载好的APK文件
*/
private void openAPK() {
String fileName = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS).getPath() +
downloadUrl.substring(downloadUrl.lastIndexOf("/"));
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri contentUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
contentUri = FileProvider.getUriForFile(this,"com.jshaz.daigo.fileprovider",new File(fileName));
} else {
contentUri = Uri.fromFile(new File(fileName));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
intent.setDataAndType(contentUri,"application/vnd.android.package-archive");
startActivity(intent);
}
项目:maktabkhoone-instagram
文件:ShareImageActivity.java
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);
}
}
}
项目:cda-app
文件:ChatActivity.java
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);
}
项目:OSchina_resources_android
文件:OpenBuilder.java
/**
* 单纯分享图片
*/
private void share(Bitmap bitmap,int scene) {
try {
String url = saveShare(bitmap);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
Uri uri = FileProvider.getUriForFile(activity,"net.oschina.app.provider",new File(url));
intent.putExtra(Intent.EXTRA_STREAM,uri);//uri为你要分享的图片的uri
intent.setType("image/*");
intent.setClassName("com.tencent.mm",scene == SendMessagetoWX.Req.WXSceneTimeline ?
"com.tencent.mm.ui.tools.SharetoTimeLineUI"
: "com.tencent.mm.ui.tools.ShareImgUI");
activity.startActivityForResult(intent,1);
}catch (Exception e){
e.printstacktrace();
Toast.makeText(activity,"请安装微信",Toast.LENGTH_SHORT).show();
}
}
项目:Bailan
文件:AppInfoUtils.java
public static void install(String path,File apkFile) {
Intent installIntent = new Intent(Intent.ACTION_VIEW);
//判断是否是AndroidN以及更高的版本
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
installIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri contentUri = FileProvider.getUriForFile(UIUtils.getContext(),com.example.ggxiaozhi.store.the_basket.BuildConfig.APPLICATION_ID + ".fileProvider",apkFile);
installIntent.setDataAndType(contentUri,"application/vnd.android.package-archive");
} else {
installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
installIntent.setDataAndType(Uri.parse("file://" + path),"application/vnd.android.package-archive");
}
UIUtils.getContext().startActivity(installIntent);
}
项目:HybridForAndroid
文件:Utils.java
/**
* 处理7.0兼容问题
* @param context
* @param file
*/
public static void installApk(Context context,File file) {
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data;
// 判断版本大于等于7.0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// "net.csdn.blog.ruancoder.fileprovider"即是在清单文件中配置的authorities
data = FileProvider.getUriForFile(context,"com.example.jianqiang.hybridapp.fileprovider",file);
// 给目标应用一个临时授权
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
data = Uri.fromFile(file);
}
intent.setDataAndType(data,"application/vnd.android.package-archive");
context.startActivity(intent);
}
项目:Matisse-Image-and-Video-Selector
文件:MediaStoreCompat.java
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);
}
}
}
}
项目:Saiy-PS
文件:UtilsFile.java
/**
* Convert a raw resource to a file on the private storage
*
* @param ctx the application context
* @param resourceId the resource identifier
* @return the file or null if the process Failed
*/
public static File oggToCacheAndGrant(@NonNull final Context ctx,final int resourceId,final String packageName) {
final String cachePath = getPrivateDirPath(ctx);
if (Utilsstring.notNaked(cachePath)) {
final String name = ctx.getResources().getResourceEntryName(resourceId);
final File file = resourcetoFile(ctx,resourceId,new File(cachePath + SOUND_EFFECT_DIR + name
+ "." + Constants.OGG_AUdio_FILE_SUFFIX));
if (file != null) {
if (DEBUG) {
MyLog.i(CLS_NAME,"wavToCacheAndGrant file exists: " + file.exists());
MyLog.i(CLS_NAME,"wavToCacheAndGrant file path: " + file.getAbsolutePath());
}
final Uri contentUri = FileProvider.getUriForFile(ctx,FILE_PROVIDER,file);
ctx.grantUriPermission(packageName,contentUri,Intent.FLAG_GRANT_READ_URI_PERMISSION);
return file;
} else {
if (DEBUG) {
MyLog.e(CLS_NAME,"wavToCacheAndGrant file null");
}
}
} else {
if (DEBUG) {
MyLog.e(CLS_NAME,"wavToCacheAndGrant Failed to get any path");
}
}
return null;
}
项目:RetroMusicPlayer
文件:MusicUtil.java
@NonNull
public static Intent createShareSongFileIntent(@NonNull final Song song,Context context) {
try {
return new Intent()
.setAction(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_STREAM,FileProvider.getUriForFile(context,context.getApplicationContext().getPackageName(),new File(song.data)))
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
.setType("audio/*");
} catch (IllegalArgumentException e) {
// Todo the path is most likely not like /storage/emulated/0/... but something like /storage/28C7-75B0/...
e.printstacktrace();
Toast.makeText(context,"Could not share this file,I'm aware of the issue.",Toast.LENGTH_SHORT).show();
return new Intent();
}
}
项目:PimPam
文件:CameraUtils.java
private static void dispatchTakePictureIntent(final Activity activity,final Context context,final BaseFragment fragment) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(context.getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile(context);
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(context,"jcollado.pw.pimpam.fileprovider",photoURI);
if(fragment!=null) fragment.startActivityForResult(takePictureIntent,CAMERA_PICK);
else{
activity.startActivityForResult(takePictureIntent,CAMERA_PICK);
}
}
}
}
private Uri getExternalStorageUri() {
Uri uri = null;
try {
File directory = new File(getExternalFilesDir(null),"images");
if (!directory.exists()) {
if (!directory.mkdir()) {
throw new IOException();
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",Locale.getDefault()).format(new Date());
File file = File.createTempFile(timeStamp,".jpg",directory);
uri = FileProvider.getUriForFile(MainActivity.this,AUTHORITY,file);
} catch (IOException e) {
Toast.makeText(this,getString(R.string.output_file_error),Toast.LENGTH_LONG).show();
}
return uri;
}
项目:MiPushFramework
文件:LogUtils.java
public static void shareFile (Context context) {
File file = new File(getLogFile(context));
if (!file.exists() || file.length() <= 0) {
Toast.makeText(context,R.string.log_none,Toast.LENGTH_SHORT).show();
return;
}
Intent result = new Intent(Intent.ACTION_SEND);
result.setType("text/*");
try {
Uri fileUri = FileProvider.getUriForFile(
context,Constants.AUTHORITY_FILE_PROVIDER,file);
result.addFlags(
Intent.FLAG_GRANT_READ_URI_PERMISSION);
result.putExtra(Intent.EXTRA_STREAM,fileUri);
context.startActivity(result);
} catch (Exception e) {
e.printstacktrace();
Toast.makeText(context,context.getString(R.string.log_share_error,e.getMessage()),Toast.LENGTH_SHORT).show();
}
}
项目:AmenEye
文件:ChoosePhotoActivity.java
/**
* 拍照
*/
private void takePhoto() {
try {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File file = new File(ViewUtil.getAppFile(this,"images"));
File mPhotoFile = new File(ViewUtil.getAppFile(this,"images/user_take.jpg"));
if (!file.exists()) {
boolean result = file.mkdirs();
if (!mPhotoFile.exists()) {
boolean b = mPhotoFile.createNewFile();
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri contentUri = FileProvider.getUriForFile(this,"cn.aaronyi.ameneye.fileprovider",contentUri);
} else {
intent.putExtra(MediaStore.EXTRA_OUTPUT,ACTION_TAKE_PHOTO);
} catch (Exception e) {
e.printstacktrace();
}
}
项目:UpdateLibrary
文件:UpdateDialog.java
/**
* 安装软件
*/
private void installApk() {
if (apkFile == null || !apkFile.exists()) {
startDownApk();
} else {
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(apkFile);
} else {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
data = FileProvider.getUriForFile(mContext,"com.ruiiqn.update.fileprovider",apkFile);
}
intent.setDataAndType(data,type);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
}
项目:GCSApp
文件:CreateCircleActivity.java
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,uri);
}else {
intent.putExtra(MediaStore.EXTRA_OUTPUT,1);
} catch (Exception e) {
}
}
项目:BaseCore
文件:DownloadService.java
/**
* 通过隐式意图调用系统安装程序安装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");
}
context.startActivity(intent);
}
项目:GCSApp
文件:CircleInfoActivity.java
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,1);
} catch (Exception e) {
}
}
项目:Clases-2017c1
文件:SelectPictureActivity.java
private void takePicture() {
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,"ar.edu.utn.frba.myapplication.fileprovider",photoFile);
grantPermissionsToUri(this,takePictureIntent,photoURI);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,REQUEST_TAKE_PHOTO);
}
}
}
项目:REDAndroid
文件:ReleaseActivity.java
@Override
public void showDownloadComplete(File file) {
Uri uri = FileProvider.getUriForFile(this,BuildConfig.APPLICATION_ID + ".provider",file);
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
intent.setDataAndType(uri,"application/x-bittorrent");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_rippy)
.setContentTitle("Download complete")
.setContentText(file.getName());
PendingIntent contentIntent = PendingIntent.getActivity(this,intent,PendingIntent.FLAG_CANCEL_CURRENT);
mBuilder.setongoing(false);
mBuilder.setContentIntent(contentIntent);
notificationmanager mnotificationmanager =
(notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE);
mnotificationmanager.notify(file.hashCode(),mBuilder.build());
}
项目:quire
文件:UpdateUserListingActivity.java
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);
}
}
}
@Override
public void whenReceived(Procedure<Result<Uri>> callback) {
intentManager.registerOnActivityResult(requestCodeCamera,activityResult -> {
if (activityResult.getResultCode() != Activity.RESULT_OK) {
callback.apply(Result.<Uri>create().put("code",activityResult.getRequestCode()).setThrowable(new RuntimeException("unsupported result code: " + activityResult.getRequestCode())));
} else {
if (getCameraTmpFile().length() > 0) {
Uri photoURI = FileProvider.getUriForFile(permissions.getActivity(),getAuthority(),getCameraTmpFile());
callback.apply(Result.create(photoURI));
} else {
asyncParseUris(scope,activityResult.getData()).whenDone(resList -> {
if (resList.exists() && resList.get().size() > 0) {
callback.apply(Result.create(resList.get().get(0)));
} else {
callback.apply(Result.nullValue(resList));
}
});
}
}
return true;
});
}
protected void showNotification(String notificationText) {
// Todo Auto-generated method stub
NotificationCompat.Builder build = new NotificationCompat.Builder(
activity);
build.setSmallIcon(OnesheeldApplication.getNotificationIcon());
build.setContentTitle(activity.getString(R.string.data_logger_shield_name));
build.setContentText(notificationText);
build.setTicker(notificationText);
build.setWhen(System.currentTimeMillis());
build.setAutoCancel(true);
Toast.makeText(activity,notificationText,Toast.LENGTH_SHORT).show();
Vibrator v = (Vibrator) activity
.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(1000);
Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String mimeFileType = mimeTypeMap.getMimeTypeFromExtension("csv");
if(Build.VERSION.SDK_INT>=24) {
Uri fileURI = FileProvider.getUriForFile(activity,new File(filePath == null || filePath.length() == 0 ? "" : filePath));
notificationIntent.setDataAndType(fileURI,mimeFileType);
}
else{
notificationIntent.setDataAndType(Uri.fromFile(new File(filePath == null
|| filePath.length() == 0 ? "" : filePath)),mimeFileType);
}
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
PendingIntent intent = PendingIntent.getActivity(activity,notificationIntent,0);
build.setContentIntent(intent);
Notification notification = build.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationmanager notificationmanager = (notificationmanager) activity
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify((int) new Date().getTime(),notification);
}
项目:ishealthy
文件:MainActivity.java
@Override
public void onActivityResult(int requestCode,int resultCode,Intent data) {
super.onActivityResult(requestCode,resultCode,data);
if (resultCode != RESULT_OK) {
return;
}
if (requestCode == REQUEST_IMAGE_CAPTURE) {
mDialog = ProgressDialog.show(this,"",getString(R.string.progress_dialog),true);
Uri uri = FileProvider.getUriForFile(this,mPhotoFile);
this.revokeUriPermission(uri,Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
try {
PictureUtils.compressBitmap(mPhotoFile);
} catch (IOException e) {
e.printstacktrace();
}
callAPI();
}
}
项目:Simpler
文件:ImageSelectFragment.java
private void showCameraAction() {
if (config.maxnum <= Global.imageList.size()) {
AppToast.showToast(String.format(getString(R.string.max_num),config.maxnum));
return;
}
if (ContextCompat.checkSelfPermission(getActivity(),Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CAMERA},CAMERA_REQUEST_CODE);
return;
}
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getActivity().getPackageManager()) != null) {
tempFile = new File(FileUtils.getRootPath(getActivity()) + File.separator
+ getActivity().getString(R.string.app_name) + "_" + System.currentTimeMillis() + ".jpg");
// 创建临时照片文件
FileUtils.createFile(tempFile);
Uri uri = FileProvider.getUriForFile(getActivity(),FileUtils.getApplicationId(getActivity()) + ".provider",tempFile);
List<ResolveInfo> resInfoList = getActivity().getPackageManager()
.queryIntentActivities(cameraIntent,PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
getActivity().grantUriPermission(packageName,Intent.FLAG_GRANT_WRITE_URI_PERMISSION
| Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
startActivityForResult(cameraIntent,REQUEST_CAMERA);
} else {
AppToast.showToast(R.string.open_camera_failure);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。