先上图:
用法
使用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>
在您的活动或任何地方:
他们将要求三个必要的权限:CAMERA
,ACCESS_FINE_LOCATION
和WRITE_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
已经为你准备好了
日历 | 相机 | 联络人 | 位置 | |
---|---|---|---|---|
drawableId | Permission_ic_calendar | Permission_ic_camera | Permission_ic_contacts | Permission_ic_location |
麦克风 | 电话 | 短信 | 存储 | 感测器 | |
---|---|---|---|---|---|
drawableId | Permission_ic_micro_phone | Permission_ic_phone | Permission_ic_sms | Permission_ic_storage | Permission_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