• Kotlin高仿微信-第7篇-主页-动态权限申请


     Kotlin高仿微信-项目实践58篇详细讲解了各个功能点,包括:注册、登录、主页、单聊(文本、表情、语音、图片、小视频、视频通话、语音通话、红包、转账)、群聊、个人信息、朋友圈、支付服务、扫一扫、搜索好友、添加好友、开通VIP等众多功能。

    Kotlin高仿微信-项目实践58篇,点击查看详情

    效果图:

    实现代码:

    private fun handlePermission(){
        var permissions = arrayOf(
            Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO,
            Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_PHONE_STATE)
    
        var isGranted = true
        for (i in permissions.indices){
            var permission = permissions[i]
            if(!checkPermission(permission)){
                isGranted = false
                break
            }
        }
    
        if(!isGranted){
            requestPermissions(permissions, 88)
        }
    }
    
    fun checkPermission(permission: String) :Boolean {
        return ContextCompat.checkSelfPermission(WcApp.getContext(), permission) == PackageManager.PERMISSION_GRANTED
    }
    
    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        if(requestCode == 88 && grantResults != null && grantResults.size > 0){
            (fragments.get(TAB_WECHAT) as WeChatFragment).refresh()
            (fragments.get(TAB_CONTACTS) as ContactsFragment).refresh()
            (fragments.get(TAB_ME) as MeFragment).refresh()
            processNotification()
        }
    }
    
    
    /**
     * 判断手机通知栏是否启用, 如果不启用,跳转到页面开启
     */
    private fun processNotification(){
        var account = DataStoreUtils.getAccount()
        TagUtils.d("viewpager是否启用:${ChatNotificationUtils.isNotificationEnabled()}")
        if(!TextUtils.isEmpty(account) && !ChatNotificationUtils.isNotificationEnabled()){
            NotificationSettingMsg().showNotificationSetting(requireActivity(), viewpager_container_root, false, object : BasePopupWindow.IOnDismissListener{
                override fun onDismiss() {
                    //
                }
            })
        }
    }

  • 相关阅读:
    JAVA+Web+应用开发技术与案例教程第2版张继军第七章Java Web 常用开发模式与案例课后习题
    微信小程序-云开发 起步
    LabVIEW用户界面设计
    cmake应用:集成gtest进行单元测试
    MindSpore:【语音识别】DFCNN网络训练loss不收敛
    Qt 序列化函数和反序列化函数
    单片机、DSP、ARM、FPGA,它们都能干什么
    【C++】类和对象(下)
    file和FileReader之间的关系
    Android调用相机拍照,展示拍摄的图片
  • 原文地址:https://blog.csdn.net/maoning20080808/article/details/128089990