Android开发询问通知栏权限功能

94 阅读1分钟
Android开发询问通知栏权限功能

是否有通知栏权限,牵扯到是否有通知栏提醒,很关键的

一、思路:

(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).importance == NotificationManager.IMPORTANCE_NONE

二、效果图:

在这里插入图片描述在这里插入图片描述

三、关键代码:
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)


        val mContext = this
        findViewById<View>(R.id.tv_notification).setOnClickListener {
            //通知栏权限是否开启
            if (!isNotificationEnabled(mContext)) {
                BaseDialogUtils.okAndCancel(
                    mContext,
                    getString(R.string.request_notify_permission_tip),
                    title = getString(R.string.tip),
                    ok = getString(R.string.ok_go_setting),
                    okListener = { startAppSetting(mContext) }
                )
            } else {
                Toast.makeText(mContext,"已经有通知权限",Toast.LENGTH_LONG).show()
            }
        }

    }
四、项目demo源码结构图:

在这里插入图片描述

有问题或者需要完整源码demo的可以看简介联系我,也可以私信我,我每天都看私信的