├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── assets
│ │ │ ├── GIF.gif
│ │ │ └── GIF2.gif
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable
│ │ │ │ └── circle.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── xml
│ │ │ │ └── file_paths.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── choicemmed
│ │ │ └── com
│ │ │ └── android60permissionsdemo
│ │ │ ├── ToastUtils.java
│ │ │ ├── MainActivity.java
│ │ │ └── PhotoUtils.java
│ ├── test
│ │ └── java
│ │ │ └── choicemmed
│ │ │ └── com
│ │ │ └── android60permissionsdemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── choicemmed
│ │ └── com
│ │ └── android60permissionsdemo
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── encodings.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/assets/GIF.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhengzhong1/Android6.0PermissionsDemo/HEAD/app/src/main/assets/GIF.gif
--------------------------------------------------------------------------------
/app/src/main/assets/GIF2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhengzhong1/Android6.0PermissionsDemo/HEAD/app/src/main/assets/GIF2.gif
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Android6.0PermissionsDemo
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhengzhong1/Android6.0PermissionsDemo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhengzhong1/Android6.0PermissionsDemo/HEAD/app/src/main/res/drawable/circle.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhengzhong1/Android6.0PermissionsDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhengzhong1/Android6.0PermissionsDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhengzhong1/Android6.0PermissionsDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhengzhong1/Android6.0PermissionsDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhengzhong1/Android6.0PermissionsDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/file_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android6.0PermissionsDemo
2 | Android拍照、相册访问图片剪裁适配到Android7.0,Android7.0中尝试传递 file:// URI 会触发 FileUriExposedException,因为在Android7.0之后Google认为直接使用本地的根目录即file:// URI是不安全的操作,直接访问会抛出FileUriExposedExCeption异常,这就意味着在Android7.0以前我们访问相机拍照存储时,如果使用URI的方式直接存储剪裁图片就会造成这个异常.
3 | * 调用系统相机拍照
4 |
5 | 
6 |
7 | * 打开系统相册
8 |
9 | 
10 |
--------------------------------------------------------------------------------
/app/src/test/java/choicemmed/com/android60permissionsdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package choicemmed.com.android60permissionsdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\androidSDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/choicemmed/com/android60permissionsdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package choicemmed.com.android60permissionsdemo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("choicemmed.com.android60permissionsdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.2"
6 | defaultConfig {
7 | applicationId "choicemmed.com.android60permissionsdemo"
8 | minSdkVersion 19
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:24.2.1'
28 | testCompile 'junit:junit:4.12'
29 | compile 'com.jiechic.library:xUtils:2.6.14'
30 | compile 'de.hdodenhof:circleimageview:2.0.0'
31 | compile 'com.google.android.gms:play-services-appindexing:8.4.0'
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
20 |
21 |
29 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
24 |
27 |
32 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/java/choicemmed/com/android60permissionsdemo/ToastUtils.java:
--------------------------------------------------------------------------------
1 | package choicemmed.com.android60permissionsdemo;
2 |
3 | import android.content.Context;
4 | import android.view.ViewGroup;
5 | import android.widget.Toast;
6 |
7 | /**
8 | * Toast统一管理类
9 | *
10 | */
11 | public class ToastUtils
12 | {
13 |
14 | private ViewGroup.LayoutParams layoutParams;
15 |
16 | private ToastUtils()
17 | {
18 | /* cannot be instantiated */
19 | throw new UnsupportedOperationException("cannot be instantiated");
20 | }
21 |
22 | public static boolean isShow = true;
23 |
24 | /**
25 | * 短时间显示Toast
26 | *
27 | * @param context
28 | * @param message
29 | */
30 | public static void showShort(Context context, CharSequence message)
31 | {
32 | if (isShow)
33 | Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
34 | }
35 |
36 | /**
37 | * 短时间显示Toast
38 | *
39 | * @param context
40 | * @param message
41 | */
42 | public static void showShort(Context context, int message)
43 | {
44 | if (isShow)
45 | Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
46 | }
47 |
48 | /**
49 | * 长时间显示Toast
50 | *
51 | * @param context
52 | * @param message
53 | */
54 | public static void showLong(Context context, CharSequence message)
55 | {
56 | if (isShow)
57 | Toast.makeText(context, message, Toast.LENGTH_LONG).show();
58 | }
59 |
60 | /**
61 | * 长时间显示Toast
62 | *
63 | * @param context
64 | * @param message
65 | */
66 | public static void showLong(Context context, int message)
67 | {
68 | if (isShow)
69 | Toast.makeText(context, message, Toast.LENGTH_LONG).show();
70 | }
71 |
72 | /**
73 | * 自定义显示Toast时间
74 | *
75 | * @param context
76 | * @param message
77 | * @param duration
78 | */
79 | public static void show(Context context, CharSequence message, int duration)
80 | {
81 | if (isShow)
82 | Toast.makeText(context, message, duration).show();
83 | }
84 |
85 | /**
86 | * 自定义显示Toast时间
87 | *
88 | * @param context
89 | * @param message
90 | * @param duration
91 | */
92 | public static void show(Context context, int message, int duration)
93 | {
94 | if (isShow)
95 | Toast.makeText(context, message, duration).show();
96 | }
97 |
98 |
99 |
100 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/choicemmed/com/android60permissionsdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package choicemmed.com.android60permissionsdemo;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.content.pm.PackageManager;
6 | import android.graphics.Bitmap;
7 | import android.net.Uri;
8 | import android.os.Build;
9 | import android.os.Bundle;
10 | import android.os.Environment;
11 | import android.support.annotation.NonNull;
12 | import android.support.v4.app.ActivityCompat;
13 | import android.support.v4.content.ContextCompat;
14 | import android.support.v4.content.FileProvider;
15 | import android.support.v7.app.AppCompatActivity;
16 | import android.view.View;
17 | import android.widget.Button;
18 |
19 | import com.lidroid.xutils.ViewUtils;
20 | import com.lidroid.xutils.view.annotation.ViewInject;
21 | import com.lidroid.xutils.view.annotation.event.OnClick;
22 |
23 | import java.io.File;
24 |
25 | import de.hdodenhof.circleimageview.CircleImageView;
26 |
27 | /**
28 | * @author zhengzhong on 2016/8/6 16:16
29 | * Email zheng_zhong@163.com
30 | */
31 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
32 | private static final String TAG = "MainActivity";
33 | @ViewInject(R.id.photo)
34 | private CircleImageView photo;
35 | @ViewInject(R.id.takePic)
36 | private Button takePic;
37 | @ViewInject(R.id.takeGallery)
38 | private Button takeGallery;
39 | private static final int CODE_GALLERY_REQUEST = 0xa0;
40 | private static final int CODE_CAMERA_REQUEST = 0xa1;
41 | private static final int CODE_RESULT_REQUEST = 0xa2;
42 | private static final int CAMERA_PERMISSIONS_REQUEST_CODE = 0x03;
43 | private static final int STORAGE_PERMISSIONS_REQUEST_CODE = 0x04;
44 | private File fileUri = new File(Environment.getExternalStorageDirectory().getPath() + "/photo.jpg");
45 | private File fileCropUri = new File(Environment.getExternalStorageDirectory().getPath() + "/crop_photo.jpg");
46 | private Uri imageUri;
47 | private Uri cropImageUri;
48 |
49 | @Override
50 | protected void onCreate(Bundle savedInstanceState) {
51 | super.onCreate(savedInstanceState);
52 | setContentView(R.layout.activity_main);
53 | ViewUtils.inject(this);
54 | }
55 |
56 |
57 | @OnClick({R.id.takePic, R.id.takeGallery})
58 | @Override
59 | public void onClick(View v) {
60 | switch (v.getId()) {
61 | case R.id.takePic:
62 | autoObtainCameraPermission();
63 | break;
64 | case R.id.takeGallery:
65 | autoObtainStoragePermission();
66 | break;
67 | default:
68 | }
69 | }
70 |
71 | /**
72 | * 自动获取相机权限
73 | */
74 | private void autoObtainCameraPermission() {
75 |
76 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED
77 | || ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
78 |
79 | if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
80 | ToastUtils.showShort(this, "您已经拒绝过一次");
81 | }
82 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE}, CAMERA_PERMISSIONS_REQUEST_CODE);
83 | } else {//有权限直接调用系统相机拍照
84 | if (hasSdcard()) {
85 | imageUri = Uri.fromFile(fileUri);
86 | //通过FileProvider创建一个content类型的Uri
87 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
88 | imageUri = FileProvider.getUriForFile(MainActivity.this, "com.zz.fileprovider", fileUri);
89 | }
90 | PhotoUtils.takePicture(this, imageUri, CODE_CAMERA_REQUEST);
91 | } else {
92 | ToastUtils.showShort(this, "设备没有SD卡!");
93 | }
94 | }
95 | }
96 |
97 | @Override
98 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
99 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
100 |
101 | switch (requestCode) {
102 | //调用系统相机申请拍照权限回调
103 | case CAMERA_PERMISSIONS_REQUEST_CODE: {
104 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
105 | if (hasSdcard()) {
106 | imageUri = Uri.fromFile(fileUri);
107 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
108 | imageUri = FileProvider.getUriForFile(MainActivity.this, "com.zz.fileprovider", fileUri);//通过FileProvider创建一个content类型的Uri
109 | PhotoUtils.takePicture(this, imageUri, CODE_CAMERA_REQUEST);
110 | } else {
111 | ToastUtils.showShort(this, "设备没有SD卡!");
112 | }
113 | } else {
114 |
115 | ToastUtils.showShort(this, "请允许打开相机!!");
116 | }
117 | break;
118 |
119 |
120 | }
121 | //调用系统相册申请Sdcard权限回调
122 | case STORAGE_PERMISSIONS_REQUEST_CODE:
123 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
124 | PhotoUtils.openPic(this, CODE_GALLERY_REQUEST);
125 | } else {
126 |
127 | ToastUtils.showShort(this, "请允许打操作SDCard!!");
128 | }
129 | break;
130 | default:
131 | }
132 | }
133 |
134 | private static final int OUTPUT_X = 480;
135 | private static final int OUTPUT_Y = 480;
136 |
137 | @Override
138 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
139 | super.onActivityResult(requestCode, resultCode, data);
140 |
141 | if (resultCode == RESULT_OK) {
142 | switch (requestCode) {
143 | //拍照完成回调
144 | case CODE_CAMERA_REQUEST:
145 | cropImageUri = Uri.fromFile(fileCropUri);
146 | PhotoUtils.cropImageUri(this, imageUri, cropImageUri, 1, 1, OUTPUT_X, OUTPUT_Y, CODE_RESULT_REQUEST);
147 | break;
148 | //访问相册完成回调
149 | case CODE_GALLERY_REQUEST:
150 | if (hasSdcard()) {
151 | cropImageUri = Uri.fromFile(fileCropUri);
152 | Uri newUri = Uri.parse(PhotoUtils.getPath(this, data.getData()));
153 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
154 | newUri = FileProvider.getUriForFile(this, "com.zz.fileprovider", new File(newUri.getPath()));
155 | }
156 | PhotoUtils.cropImageUri(this, newUri, cropImageUri, 1, 1, OUTPUT_X, OUTPUT_Y, CODE_RESULT_REQUEST);
157 | } else {
158 | ToastUtils.showShort(this, "设备没有SD卡!");
159 | }
160 | break;
161 | case CODE_RESULT_REQUEST:
162 | Bitmap bitmap = PhotoUtils.getBitmapFromUri(cropImageUri, this);
163 | if (bitmap != null) {
164 | showImages(bitmap);
165 | }
166 | break;
167 | default:
168 | }
169 | }
170 | }
171 |
172 |
173 | /**
174 | * 自动获取sdk权限
175 | */
176 |
177 | private void autoObtainStoragePermission() {
178 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
179 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, STORAGE_PERMISSIONS_REQUEST_CODE);
180 | } else {
181 | PhotoUtils.openPic(this, CODE_GALLERY_REQUEST);
182 | }
183 |
184 | }
185 |
186 | private void showImages(Bitmap bitmap) {
187 | photo.setImageBitmap(bitmap);
188 | }
189 |
190 | /**
191 | * 检查设备是否存在SDCard的工具方法
192 | */
193 | public static boolean hasSdcard() {
194 | String state = Environment.getExternalStorageState();
195 | return state.equals(Environment.MEDIA_MOUNTED);
196 | }
197 |
198 |
199 | }
200 |
--------------------------------------------------------------------------------
/app/src/main/java/choicemmed/com/android60permissionsdemo/PhotoUtils.java:
--------------------------------------------------------------------------------
1 | package choicemmed.com.android60permissionsdemo;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.content.ContentUris;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.database.Cursor;
9 | import android.graphics.Bitmap;
10 | import android.net.Uri;
11 | import android.os.Build;
12 | import android.os.Environment;
13 | import android.provider.DocumentsContract;
14 | import android.provider.MediaStore;
15 |
16 | /**
17 | * @author zhengzhong on 2016/8/6 16:16
18 | * Email zheng_zhong@163.com
19 | */
20 | public class PhotoUtils {
21 | private static final String TAG = "PhotoUtils";
22 |
23 | /**
24 | * @param activity 当前activity
25 | * @param imageUri 拍照后照片存储路径
26 | * @param requestCode 调用系统相机请求码
27 | */
28 | public static void takePicture(Activity activity, Uri imageUri, int requestCode) {
29 | //调用系统相机
30 | Intent intentCamera = new Intent();
31 | intentCamera.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
32 | //将拍照结果保存至photo_file的Uri中,不保留在相册中
33 | intentCamera.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
34 | activity.startActivityForResult(intentCamera, requestCode);
35 | }
36 |
37 | /**
38 | * @param activity 当前activity
39 | * @param requestCode 打开相册的请求码
40 | */
41 | public static void openPic(Activity activity, int requestCode) {
42 | Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
43 | photoPickerIntent.setType("image/*");
44 | activity.startActivityForResult(photoPickerIntent, requestCode);
45 | }
46 |
47 | /**
48 | * @param activity 当前activity
49 | * @param orgUri 剪裁原图的Uri
50 | * @param desUri 剪裁后的图片的Uri
51 | * @param aspectX X方向的比例
52 | * @param aspectY Y方向的比例
53 | * @param width 剪裁图片的宽度
54 | * @param height 剪裁图片高度
55 | * @param requestCode 剪裁图片的请求码
56 | */
57 | public static void cropImageUri(Activity activity, Uri orgUri, Uri desUri, int aspectX, int aspectY, int width, int height, int requestCode) {
58 | Intent intent = new Intent("com.android.camera.action.CROP");
59 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
60 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
61 | }
62 | intent.setDataAndType(orgUri, "image/*");
63 | //发送裁剪信号
64 | intent.putExtra("crop", "true");
65 | intent.putExtra("aspectX", aspectX);
66 | intent.putExtra("aspectY", aspectY);
67 | intent.putExtra("outputX", width);
68 | intent.putExtra("outputY", height);
69 | intent.putExtra("scale", true);
70 | //将剪切的图片保存到目标Uri中
71 | intent.putExtra(MediaStore.EXTRA_OUTPUT, desUri);
72 | //1-false用uri返回图片
73 | //2-true直接用bitmap返回图片(此种只适用于小图片,返回图片过大会报错)
74 | intent.putExtra("return-data", false);
75 | intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
76 | intent.putExtra("noFaceDetection", true);
77 | activity.startActivityForResult(intent, requestCode);
78 | }
79 |
80 | /**
81 | * 读取uri所在的图片
82 | *
83 | * @param uri 图片对应的Uri
84 | * @param mContext 上下文对象
85 | * @return 获取图像的Bitmap
86 | */
87 | public static Bitmap getBitmapFromUri(Uri uri, Context mContext) {
88 | try {
89 | Bitmap bitmap = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), uri);
90 | return bitmap;
91 | } catch (Exception e) {
92 | e.printStackTrace();
93 | return null;
94 | }
95 | }
96 |
97 | /**
98 | * @param context 上下文对象
99 | * @param uri 当前相册照片的Uri
100 | * @return 解析后的Uri对应的String
101 | */
102 | @SuppressLint("NewApi")
103 | public static String getPath(final Context context, final Uri uri) {
104 |
105 | final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
106 | String pathHead = "file:///";
107 | // DocumentProvider
108 | if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
109 | // ExternalStorageProvider
110 | if (isExternalStorageDocument(uri)) {
111 | final String docId = DocumentsContract.getDocumentId(uri);
112 | final String[] split = docId.split(":");
113 | final String type = split[0];
114 | if ("primary".equalsIgnoreCase(type)) {
115 | return pathHead + Environment.getExternalStorageDirectory() + "/" + split[1];
116 | }
117 | }
118 | // DownloadsProvider
119 | else if (isDownloadsDocument(uri)) {
120 |
121 | final String id = DocumentsContract.getDocumentId(uri);
122 |
123 | final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
124 |
125 | return pathHead + getDataColumn(context, contentUri, null, null);
126 | }
127 | // MediaProvider
128 | else if (isMediaDocument(uri)) {
129 | final String docId = DocumentsContract.getDocumentId(uri);
130 | final String[] split = docId.split(":");
131 | final String type = split[0];
132 |
133 | Uri contentUri = null;
134 | if ("image".equals(type)) {
135 | contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
136 | } else if ("video".equals(type)) {
137 | contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
138 | } else if ("audio".equals(type)) {
139 | contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
140 | }
141 |
142 | final String selection = "_id=?";
143 | final String[] selectionArgs = new String[]{split[1]};
144 |
145 | return pathHead + getDataColumn(context, contentUri, selection, selectionArgs);
146 | }
147 | }
148 | // MediaStore (and general)
149 | else if ("content".equalsIgnoreCase(uri.getScheme())) {
150 | return pathHead + getDataColumn(context, uri, null, null);
151 | }
152 | // File
153 | else if ("file".equalsIgnoreCase(uri.getScheme())) {
154 | return pathHead + uri.getPath();
155 | }
156 | return null;
157 | }
158 |
159 | /**
160 | * Get the value of the data column for this Uri. This is useful for
161 | * MediaStore Uris, and other file-based ContentProviders.
162 | *
163 | * @param context The context.
164 | * @param uri The Uri to query.
165 | * @param selection (Optional) Filter used in the query.
166 | * @param selectionArgs (Optional) Selection arguments used in the query.
167 | * @return The value of the _data column, which is typically a file path.
168 | */
169 | private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
170 |
171 | Cursor cursor = null;
172 | final String column = "_data";
173 | final String[] projection = {column};
174 | try {
175 | cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
176 | if (cursor != null && cursor.moveToFirst()) {
177 | final int column_index = cursor.getColumnIndexOrThrow(column);
178 | return cursor.getString(column_index);
179 | }
180 | } finally {
181 | if (cursor != null)
182 | cursor.close();
183 | }
184 | return null;
185 | }
186 |
187 | /**
188 | * @param uri The Uri to check.
189 | * @return Whether the Uri authority is ExternalStorageProvider.
190 | */
191 | private static boolean isExternalStorageDocument(Uri uri) {
192 | return "com.android.externalstorage.documents".equals(uri.getAuthority());
193 | }
194 |
195 | /**
196 | * @param uri The Uri to check.
197 | * @return Whether the Uri authority is DownloadsProvider.
198 | */
199 | private static boolean isDownloadsDocument(Uri uri) {
200 | return "com.android.providers.downloads.documents".equals(uri.getAuthority());
201 | }
202 |
203 | /**
204 | * @param uri The Uri to check.
205 | * @return Whether the Uri authority is MediaProvider.
206 | */
207 | private static boolean isMediaDocument(Uri uri) {
208 | return "com.android.providers.media.documents".equals(uri.getAuthority());
209 | }
210 |
211 | }
212 |
--------------------------------------------------------------------------------