HiPermission是Android上一个简单而漂亮的运行时权限库

先上图:

 

用法

使用Gradle:

compile 'me.weyye.hipermission:library:1.0.7'

或Maven:

<dependency>
  <groupId>me.weyye.hipermission</groupId>
  <artifactId>library</artifactId>
  <version>1.0.7</version>
  <type>pom</type>
</dependency>

在您的活动或任何地方:

他们将要求三个必要的权限:CAMERAACCESS_FINE_LOCATIONWRITE_EXTERNAL_STORAGE

HiPermission.create(context)
  .checkMutiPermission(new PermissionCallback() {
  	@Override
  	public void onClose() {
  		Log.i(TAG, "onClose");
  		showToast("They cancelled our request");
  	}

  	@Override
  	public void onFinish() {
  		showToast("All permissions requested completed");
  	}

  	@Override
  	public void onDeny(String permission, int position) {
  		Log.i(TAG, "onDeny");
  	}

  	@Override
  	public void onGuarantee(String permission, int position) {
  		Log.i(TAG, "onGuarantee");
  	}
  });

您也可以像这样添加要请求的权限:

 private void initview() {
        List<PermissionItem> mList =new ArrayList<PermissionItem>();
        mList.add(new PermissionItem(Manifest.permission.READ_PHONE_STATE,"读取手机状态", R.drawable.permission_ic_phone));
        mList.add(new PermissionItem(Manifest.permission.RECORD_AUDIO,"录音", R.drawable.permission_ic_phone));
        mList.add(new PermissionItem(Manifest.permission.CAMERA,"照相机", R.drawable.permission_ic_camera));
        mList.add(new PermissionItem(Manifest.permission.ACCESS_FINE_LOCATION,"位置", R.drawable.permission_ic_location));
        mList.add(new PermissionItem(Manifest.permission.READ_EXTERNAL_STORAGE,"读取文件", R.drawable.permission_ic_storage));
        mList.add(new PermissionItem(Manifest.permission.WRITE_EXTERNAL_STORAGE,"写入文件", R.drawable.permission_ic_storage));
        mList.add(new PermissionItem(Manifest.permission.READ_CONTACTS,"读取联系人", R.drawable.permission_ic_contacts));

        HiPermission.create(MainActivity.this)
                .title("亲爱的用户")
                .permissions(mList)
                .filterColor(ResourcesCompat.getColor(getResources(), R.color.ls, getTheme()))//图标的颜色
                .animStyle(R.style.PermissionAnimScale)//设置动画
                .msg("此应用需要获取以下权限")
                .style(R.style.PermissionBlueStyle)
                .checkMutiPermission(new PermissionCallback() {
                    @Override
                    public void onClose() {
                        Log.e("TAG","close");
                    }

                    @Override
                    public void onFinish() {
                        //"所有权限申请完成"
                        handler.sendEmptyMessageDelayed(StaticClass.HANDLER_SPLASH,2000);

                    }

                    @Override
                    public void onDeny(String permission, int position) {

                    }

                    @Override
                    public void onGuarantee(String permission, int position) {

                    }
                });






    }

自订样式

  HiPermission.create(MainActivity.this)
                .title("亲爱的用户")
                .permissions(mList)
                .filterColor(ResourcesCompat.getColor(getResources(), R.color.ls, getTheme()))//图标的颜色
                .animStyle(R.style.PermissionAnimScale)//设置动画
                .msg("此应用需要获取以下权限")
                .style(R.style.PermissionBlueStyle)
                .checkMutiPermission(new PermissionCallback() {
                    @Override
                    public void onClose() {
                        Log.e("TAG","close");
                    }

                    @Override
                    public void onFinish() {
                        //"所有权限申请完成"
                        handler.sendEmptyMessageDelayed(StaticClass.HANDLER_SPLASH,2000);

                    }

                    @Override
                    public void onDeny(String permission, int position) {

                    }

                    @Override
                    public void onGuarantee(String permission, int position) {

                    }
                });

设置主题后,必须调用filterColor ()以设置图标的颜色,否则默认为黑色

styles.xml

 <style name="PermissionBlueStyle">
        <!--标题颜色  亲爱的用户-->
        <item name="PermissionTitleColor">@color/ls</item>
        <!--提示字颜色  此应用需要获取以下权限-->
        <item name="PermissionMsgColor">@color/ls</item>
        <!--权限字颜色-->
        <item name="PermissionItemTextColor">@color/ls</item>
        <item name="PermissionButtonBackground">@drawable/button_bg</item>
        <item name="PermissionBackround">@drawable/shape_bg_white</item>
        <item name="PermissionButtonTextColor">@android:color/white</item>
    </style>

默认图标

是否需要其他权限,但没有图标?HiPermission已经为你准备好了

日历相机联络人位置
 
drawableIdPermission_ic_calendarPermission_ic_cameraPermission_ic_contactsPermission_ic_location
 麦克风电话短信存储感测器
 
drawableIdPermission_ic_micro_phonePermission_ic_phonePermission_ic_smsPermission_ic_storagePermission_ic_sensors

使用图标

 //使用图标 R.drawable.permission_ic_phone 
 List<PermissionItem> mList =new ArrayList<PermissionItem>();
        mList.add(new PermissionItem(Manifest.permission.READ_PHONE_STATE,"读取手机状态", R.drawable.permission_ic_phone));

默认情况下,主题没有动画,您需要像这样调用animStyle():

.animStyle(R.style.PermissionAnimScale)//设置动画

OK

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值