Permalink
Browse files

进入相册选择图片 针对6.0系统做权限判断

  • Loading branch information...
1 parent 34acbd8 commit e1207c8b4a024e51bb9f4c6721b80b7ef7847274 @siwangqishiq committed Jun 16, 2016
View
@@ -6,6 +6,20 @@
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="D:/androidstudio20/gradle/gradle-2.10" />
+ <option name="modules">
+ <set>
+ <option value="$PROJECT_DIR$" />
+ <option value="$PROJECT_DIR$/demo" />
+ <option value="$PROJECT_DIR$/imageeditlibrary" />
+ </set>
+ </option>
+ <option name="myModules">
+ <set>
+ <option value="$PROJECT_DIR$" />
+ <option value="$PROJECT_DIR$/demo" />
+ <option value="$PROJECT_DIR$/imageeditlibrary" />
+ </set>
+ </option>
</GradleProjectSettings>
</option>
</component>
View
@@ -21,6 +21,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:appcompat-v7:22.2.1'
+ compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':imageeditlibrary')
}
View
@@ -82,20 +82,16 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
@@ -105,10 +101,10 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform (1)" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" />
- <orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
+ <orderEntry type="library" exported="" name="support-v4-23.2.1" level="project" />
+ <orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
+ <orderEntry type="library" exported="" name="support-annotations-23.2.1" level="project" />
<orderEntry type="library" exported="" name="universal-image-loader-1.9.4" level="project" />
- <orderEntry type="library" exported="" name="appcompat-v7-22.2.1" level="project" />
<orderEntry type="module" module-name="imageeditlibrary" exported="" />
</component>
</module>
@@ -1,17 +1,19 @@
package com.xinlan.imageeditandroid;
+import android.Manifest;
import android.annotation.TargetApi;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
+import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.DisplayMetrics;
-import android.util.FloatMath;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
@@ -22,6 +24,8 @@
import java.io.File;
public class MainActivity extends AppCompatActivity {
+ public static final int REQUEST_PERMISSON_SORAGE = 1;
+
public static final int SELECT_GALLERY_IMAGE_CODE = 7;
public static final int TAKE_PHOTO_CODE = 8;
public static final int ACTION_REQUEST_EDITIMAGE = 9;
@@ -85,12 +89,40 @@ public void onClick(View v) {
private final class SelectClick implements View.OnClickListener {
@Override
public void onClick(View v) {
- MainActivity.this.startActivityForResult(new Intent(
- MainActivity.this, SelectPictureActivity.class),
- SELECT_GALLERY_IMAGE_CODE);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ openAblumWithPermissionsCheck();
+ } else {
+ openAblum();
+ }//end if
}
}// end inner class
+ private void openAblum() {
+ MainActivity.this.startActivityForResult(new Intent(
+ MainActivity.this, SelectPictureActivity.class),
+ SELECT_GALLERY_IMAGE_CODE);
+ }
+
+ private void openAblumWithPermissionsCheck() {
+ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
+ != PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(this,
+ new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
+ REQUEST_PERMISSON_SORAGE);
+ return;
+ }
+ openAblum();
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ if (requestCode == REQUEST_PERMISSON_SORAGE
+ && grantResults.length > 0
+ && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ openAblum();
+ }//end if
+ }
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -20,7 +20,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:appcompat-v7:22.2.1'
- compile 'com.android.support:recyclerview-v7:22.2.1'
+ compile 'com.android.support:appcompat-v7:23.1.1'
+ compile 'com.android.support:recyclerview-v7:23.2.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
}
@@ -65,14 +65,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
@@ -81,15 +73,23 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.1/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.2.1/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.1/jars" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.2.1/jars" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.2.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
@@ -104,10 +104,10 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform (1)" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" />
- <orderEntry type="library" exported="" name="recyclerview-v7-22.2.1" level="project" />
- <orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" />
+ <orderEntry type="library" exported="" name="recyclerview-v7-23.2.1" level="project" />
+ <orderEntry type="library" exported="" name="support-v4-23.2.1" level="project" />
+ <orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="universal-image-loader-1.9.4" level="project" />
- <orderEntry type="library" exported="" name="appcompat-v7-22.2.1" level="project" />
+ <orderEntry type="library" exported="" name="support-annotations-23.2.1" level="project" />
</component>
</module>

0 comments on commit e1207c8

Please sign in to comment.