Skip to content

wkp111/RuntimePermission

Repository files navigation

RuntimePermission Download

Android6.0动态权限管理库,回调模式管理动态权限,无需关注申请权限各种状态,只用关心回调是否有权限,然后做不同逻辑处理!

演示图

DragGridView

Gradle集成

dependencies{
      compile 'com.wkp:RuntimePermission:1.0.6'
      //Android Studio3.0+可用以下方式
      //implementation 'com.wkp:RuntimePermission:1.0.6'
}

Note:可能存在Jcenter还在审核阶段,这时会集成失败!

使用举例

申请CAMERA权限

1.manifest配置

    <!--权限配置-->
    <uses-permission android:name="android.permission.CAMERA"/>

Note:举例权限,根据自己需求选取!

2.代码示例

//api 23
@RequiresApi(api = Build.VERSION_CODES.M)
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    /**
     * 点击获取权限
     * @param view
     */
    public void applyPermission(final View view) {
        //权限检查,回调是权限申请结果
        RuntimePermissionUtil.checkPermissions(this, RuntimePermissionUtil.CAMERA, new PermissionCallBack() {
            @Override
            public void onCheckPermissionResult(boolean hasPermission) {
                if (hasPermission) {
                    //直接做具有权限后的操作
                    Toast.makeText(MainActivity.this, "权限申请成功", Toast.LENGTH_SHORT).show();
                    ((TextView) view).setText("权限申请成功");
                }else {
                    //显示权限不具备的界面
                    Toast.makeText(MainActivity.this, "权限申请失败", Toast.LENGTH_SHORT).show();
                    ((TextView) view).setText("权限申请失败");
                }
            }
        });
    }
}

Note:权限申请采用回调模式,不用在意Android版本,内置判断所有,总是有回调,低版本默认true!

寄语

控件支持直接代码创建,还有更多API请观看RuntimePermissionUtil.java内的注释说明。
欢迎大家使用,感觉好用请给个Star鼓励一下,谢谢!
大家如果有更好的意见或建议以及好的灵感,请邮箱作者,谢谢!
QQ邮箱:1535514884@qq.com
163邮箱:15889686524@163.com
Gmail邮箱:wkp15889686524@gmail.com

版本更新

  • v1.0.6
    修复多权限申请时部分权限不显示BUG

  • v1.0.5
    内置透明界面移入库中,方便操作

  • v1.0.4
    改善内置界面显示效果,达到透明效果

  • v1.0.3
    加入内置权限申请界面

  • v1.0.2
    新创建Android6.0动态权限管理库

License

Copyright 2017 wkp

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.

About

Android6.0动态权限管理库

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages