如何创建许可通知渠道。

发布于 2025-01-22 17:09:27 字数 1365 浏览 2 评论 0原文

根据Android文档,我正在处理一项需要从日历中读取数据的任务,我补充说,

<uses-permission android:name="android.permission.READ_CALENDAR" />

但是现在,当我使用一种方法时,

ActivityCompat.checkSelfPermission(this,
                Manifest.permission.READ_CALENDAR)

它始终返回-1,并且在调查后始终拒绝许可,我发现我必须在运行时请求许可,并且在我的框架中需要批准多次许可,

我发现允许范围内

。 “ NULL”请参阅日志,以获取更多详细信息,

我尝试使用以下方法添加通知频道

   private void createNotificationChannelIfNeeded(int id, String title, String message) {
    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = title;
        String description = message;
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel channel = new NotificationChannel(title, name, importance);
        channel.setDescription(description);
        // Register the channel with the system; you can't change the importance
        // or other notification behaviors after this
        NotificationManager mNotifyMgr =
                (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
        mNotifyMgr.createNotificationChannel(channel);
    }

,但仍会遇到相同的错误。

I am working on one task where I need to read the data from calendar, as per android documentation, I added

<uses-permission android:name="android.permission.READ_CALENDAR" />

but now when I am using a method

ActivityCompat.checkSelfPermission(this,
                Manifest.permission.READ_CALENDAR)

it is always returning -1, and permission is denial always, After investigation, I found that I have to request permission at run time, and there are multiple permission required to be granted in my framework,

I found that PermissionEverywhere.getpermission, can solve this issue,

but I am getting error "Developer warning for package Failed to post notification on channel "null" see log for more details

I tried adding the notification channel using below method

   private void createNotificationChannelIfNeeded(int id, String title, String message) {
    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = title;
        String description = message;
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel channel = new NotificationChannel(title, name, importance);
        channel.setDescription(description);
        // Register the channel with the system; you can't change the importance
        // or other notification behaviors after this
        NotificationManager mNotifyMgr =
                (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
        mNotifyMgr.createNotificationChannel(channel);
    }

but still getting the same error. please let me know, how to create channel for Permission everywhere class

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文