Skip to content

Commit

Permalink
Merge pull request #270 from Yalantis/feature/file_provider
Browse files Browse the repository at this point in the history
added file provider
  • Loading branch information
Cool04ek authored Mar 28, 2017
2 parents 0b4c13f + 39bed8e commit 0add52a
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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')
}
10 changes: 10 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
android:label="@string/app_name"
android:theme="@style/AppTheme">

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="@string/file_provider_authorities"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>

<activity
android:name="com.yalantis.ucrop.sample.SampleActivity"
android:screenOrientation="portrait">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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).
Expand Down Expand Up @@ -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<ResolveInfo> 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);

Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
<string name="toast_cannot_retrieve_cropped_image">Cannot retrieve cropped image</string>
<string name="toast_unexpected_error">Unexpected error</string>

<string name="file_provider_authorities">com.yalantis.ucrop.provider</string>
</resources>
4 changes: 4 additions & 0 deletions sample/src/main/res/xml/file_provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="Pictures" path="."/>
</paths>
8 changes: 4 additions & 4 deletions ucrop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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'
}

0 comments on commit 0add52a

Please sign in to comment.