From 39bed8ee8cfd5dddbe788ed64fa87b91cf762a58 Mon Sep 17 00:00:00 2001 From: Kucherenko Ihor Date: Wed, 15 Mar 2017 16:27:27 +0200 Subject: [PATCH] added file provider --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- sample/build.gradle | 8 +++---- sample/src/main/AndroidManifest.xml | 10 +++++++++ .../yalantis/ucrop/sample/ResultActivity.java | 22 ++++++++++++++++++- sample/src/main/res/values/strings.xml | 1 + .../src/main/res/xml/file_provider_paths.xml | 4 ++++ ucrop/build.gradle | 8 +++---- 8 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 sample/src/main/res/xml/file_provider_paths.xml diff --git a/build.gradle b/build.gradle index 4f31b868b..587fbc51d 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.3' + classpath 'com.android.tools.build:gradle:2.3.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fc482eb61..b671a8a27 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Sep 08 12:21:35 EEST 2016 +#Wed Mar 15 16:17:48 EET 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index 2b8a86753..a730b345f 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 24 - buildToolsVersion "24.0.2" + compileSdkVersion 25 + buildToolsVersion '25.0.0' defaultConfig { applicationId "com.yalantis.ucrop.sample" minSdkVersion 14 - targetSdkVersion 24 + targetSdkVersion 25 versionCode 10 versionName "1.2.2" } @@ -28,7 +28,7 @@ android { } dependencies { - compile 'com.android.support:appcompat-v7:24.2.0' + compile 'com.android.support:appcompat-v7:25.0.0' compile project (':ucrop') } \ No newline at end of file diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 8b44fe3d8..255885d49 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -12,6 +12,16 @@ android:label="@string/app_name" android:theme="@style/AppTheme"> + + + + diff --git a/sample/src/main/java/com/yalantis/ucrop/sample/ResultActivity.java b/sample/src/main/java/com/yalantis/ucrop/sample/ResultActivity.java index 71fc3140f..389874a6d 100755 --- a/sample/src/main/java/com/yalantis/ucrop/sample/ResultActivity.java +++ b/sample/src/main/java/com/yalantis/ucrop/sample/ResultActivity.java @@ -6,6 +6,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.graphics.BitmapFactory; import android.graphics.Color; import android.net.Uri; @@ -14,6 +15,7 @@ import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v4.app.NotificationCompat; +import android.support.v4.content.FileProvider; import android.support.v7.app.ActionBar; import android.support.v7.widget.Toolbar; import android.util.Log; @@ -28,6 +30,10 @@ import java.io.FileOutputStream; import java.nio.channels.FileChannel; import java.util.Calendar; +import java.util.List; + +import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION; +import static android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION; /** * Created by Oleksii Shliama (https://github.com/shliama). @@ -145,7 +151,21 @@ private void copyFileToDownloads(Uri croppedFileUri) throws Exception { private void showNotification(@NonNull File file) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.setDataAndType(Uri.fromFile(file), "image/*"); + Uri fileUri = FileProvider.getUriForFile( + this, + getString(R.string.file_provider_authorities), + file); + + intent.setDataAndType(fileUri, "image/*"); + + List resInfoList = getPackageManager().queryIntentActivities( + intent, + PackageManager.MATCH_DEFAULT_ONLY); + for(ResolveInfo info: resInfoList) { + grantUriPermission( + info.activityInfo.packageName, + fileUri, FLAG_GRANT_WRITE_URI_PERMISSION | FLAG_GRANT_READ_URI_PERMISSION); + } NotificationCompat.Builder mNotification = new NotificationCompat.Builder(this); diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 52e8307c1..5906493ad 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -41,4 +41,5 @@ Cannot retrieve cropped image Unexpected error + com.yalantis.ucrop.provider diff --git a/sample/src/main/res/xml/file_provider_paths.xml b/sample/src/main/res/xml/file_provider_paths.xml new file mode 100644 index 000000000..b574139aa --- /dev/null +++ b/sample/src/main/res/xml/file_provider_paths.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ucrop/build.gradle b/ucrop/build.gradle index 3a73fbebc..898bca2e8 100644 --- a/ucrop/build.gradle +++ b/ucrop/build.gradle @@ -2,12 +2,12 @@ apply plugin: 'com.android.library' apply from: '../mavenpush.gradle' android { - compileSdkVersion 24 - buildToolsVersion '24.0.2' + compileSdkVersion 25 + buildToolsVersion '25.0.0' defaultConfig { minSdkVersion 14 - targetSdkVersion 24 + targetSdkVersion 25 versionCode 22 versionName "2.2.0-native" @@ -36,6 +36,6 @@ android { } dependencies { - compile 'com.android.support:appcompat-v7:24.2.0' + compile 'com.android.support:appcompat-v7:25.0.0' compile 'com.squareup.okhttp3:okhttp:3.4.1' }