Skip to content

Commit

Permalink
Initialize project.
Browse files Browse the repository at this point in the history
  • Loading branch information
yanzhenjie committed Sep 11, 2016
0 parents commit f073310
Show file tree
Hide file tree
Showing 52 changed files with 1,799 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
/build
/sample/build/
/permission/build/
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 122 additions & 0 deletions README.md
@@ -0,0 +1,122 @@
# AndPermission

严振杰的主页:[http://www.yanzhenjie.com](http://www.yanzhenjie.com)
严振杰的博客:[http://blog.yanzhenjie.com](http://blog.yanzhenjie.com)
技术交流群:547839514,加群前请务必阅读[群行为规范](https://github.com/yanzhenjie/SkillGroupRule)

更多解释请看[Android6.0 运行时权限管理最佳实践详解](http://blog.csdn.net/yanzhenjie1003/article/details/52503533)

----

## 引用方法
* AndroidStudio使用方法,gradle一句话远程依赖
```groovy
compile 'com.yanzhenjie:permission:1.0.0'
```
Or Maven:
```xml
<dependency>
<groupId>com.yanzhenjie</groupId>
<artifactId>permission</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
```

* Eclipse [下载jar包](https://github.com/yanzhenjie/AndPermission/blob/master/jar/andpermission.jar?raw=true),或者自行下载源码。

我在开发SwipeRecyclerView时引用的RecyclerView版本如下:
```groovy
compile 'com.android.support:recyclerview-v7:23.4.0'
```

## 使用介绍
更好的例子,请下载源码后运行demo查看,这里给出最关键的代码。

1、**申请权限就是这么简单**
```java
AndPermission.with(this)
.requestCode(101)
.permission(Manifest.permission.WRITE_CONTACTS,
Manifest.permission.READ_SMS,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
.send();
```
只需要在Activity中或者Fragment中直接调用即可,AndPermission自动为你打理好后宫。

2、**接受权限回调更简单**
只需要重写Activity/Fragment的一个方法,然后提供一个授权时回调的方法即可:
```java
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
// 只需要调用这一句,剩下的AndPermission自动完成。
AndPermission.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
}

// 成功回调的方法,用注解即可,里面的数字是请求时的requestCode。
@PermissionYes(100)
private void getLocationYes() {
// 申请权限成功,可以去做点什么了。
Toast.makeText(this, "获取定位权限成功", Toast.LENGTH_SHORT).show();
}

// 失败回调的方法,用注解即可,里面的数字是请求时的requestCode。
@PermissionNo(100)
private void getLocationNo() {
// 申请权限失败,可以提醒一下用户。
Toast.makeText(this, "获取定位权限失败", Toast.LENGTH_SHORT).show();
}
```

只需要上面这么几句话即可,你就可以大刀阔斧的干了,在总结中提到的各种判断、复杂的情况AndPermission自动完成。

3、**如果你需要在用户多次拒绝权限后提示用户**
```java
AndPermission.with(this)
.requestCode(101)
.permission(Manifest.permission.WRITE_CONTACTS,
Manifest.permission.READ_SMS,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
.rationale(mRationaleListener)
.send();

private RationaleListener mRationaleListener = new RationaleListener() {
@Override
public void showRequestPermissionRationale(int requestCode, final Rationale rationale) {
new AlertDialog.Builder(RationalePermissionActivity.this)
.setTitle("友好提醒")
.setMessage("没有定位权限将不能为您推荐附近妹子,请把定位权限赐给我吧!")
.setPositiveButton("好,给你", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
rationale.resume();// 用户同意继续申请。
}
})
.setNegativeButton("我拒绝", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
rationale.cancel(); // 用户拒绝申请。
}
}).show();
}
};
```

# License
```text
Copyright 2016 Yan Zhenjie
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
14 changes: 14 additions & 0 deletions build.gradle
@@ -0,0 +1,14 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}
}

allprojects {
repositories {
jcenter()
}
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
#Fri Sep 09 20:12:33 CST 2016
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

0 comments on commit f073310

Please sign in to comment.