gpt4 book ai didi

Android通知以编程方式打开横幅设置

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:07:07 24 4
gpt4 key购买 nike

有没有办法以编程方式在应用程序通知中打开横幅设置(显示在状态栏顶部)?

enter image description here

<pre><code>
// send notification to NotificationManager
Notification.Builder notificationBuilder =new Notification.Builder(context);
notificationBuilder.setSmallIcon(R.drawable.icon_32x32)
.setLargeIcon(bitmap)
.setContentTitle("title")
.setContentText("content")
.setContentIntent(contentIntent)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(Notification.PRIORITY_HIGH)
.setCategory(Notification.CATEGORY_MESSAGE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
notificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
}

NotificationManager notificationManager =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id, notificationBuilder.build());
</code></pre>

最佳答案

同样的问题。我解决了这个问题,只需在 AndroidManifest.xml 中添加 ACCESS_NOTIFICATION_POLICY 权限即可:

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

不需要更多(至少对我而言)。

关于Android通知以编程方式打开横幅设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44711788/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com