亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通知通道 - 設置后是否可以更改 LightColor?

通知通道 - 設置后是否可以更改 LightColor?

牧羊人nacy 2022-01-19 09:19:33
我正在嘗試setLightColor使用從 JavaScript 接口返回的顏色進行更改。不幸的是,NotificationCompat.Builder(context, CHANNEL_ID).setLights對 API >= 26 絕對沒有影響,所以我不能使用Intent.putExtra或類似的東西。設置好之后還能改嗎?我希望它是動態的。編輯對我想要的東西似乎有一些誤解。我不想碰那個Broadcast Reciever。它工作得很好。我想更改通知渠道。它不更新setLightColor(Color.___)。在 protected void onCreateString jobColor = someColor; // Will be filled in by other code - different colour every timeif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {    CharSequence name = "Channel_Name";    String description = "Channel_Description";    int importance = NotificationManager.IMPORTANCE_HIGH;    NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);    channel.setDescription(description);    channel.enableLights(true);    channel.setLightColor(Color.parseColor(jobColor)); // Dynamically set from above    channel.enableVibration(true);    NotificationManager notificationManager = getSystemService(NotificationManager.class);    notificationManager.createNotificationChannel(channel);}我的 BroadcastReciever -我相信 setLight 不適用于 API 26 或更高版本public class AlarmReceiver extends BroadcastReceiver {private final String CHANNEL_ID = "some_channel";@Overridepublic void onReceive(Context context, Intent intent) {    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 , new Intent(context, MainPage.class), 0);    String jobColor = intent.getStringExtra("jobColor");}}
查看完整描述

2 回答

?
holdtom

TA貢獻1805條經驗 獲得超10個贊

您無法在不刪除頻道的情況下以編程方式更改頻道顏色通知、重要性等。

因為用戶可能已經手動更改了燈光顏色。

以編程方式實現這一點,以獲取頻道并創建一個具有新 ID 的新頻道。刪除舊頻道。如果使用以前的 id 創建頻道,您的更改將不會反映

供參考檢查WhatsApp應用程序嘗試從應用程序更改鈴聲并在左下角的頻道中查看x頻道已刪除消息

Android 文檔


查看完整回答
反對 回復 2022-01-19
?
茅侃侃

TA貢獻1842條經驗 獲得超21個贊

從 createNotificationChannel() 描述:


這也可用于恢復已刪除的頻道并更新現有頻道的 * 名稱、描述、組和/或重要性。


所以你可以試試這個:


  NotificationManager notificationManager = getSystemService(NotificationManager.class);

            //find created channel

            NotificationChannel channel = notificationManager.getNotificationChannel("id");

            if (channel != null){

                //set new color

                channel.setLightColor(0);

                //update channel

                notificationManager.createNotificationChannel(channel);

            }


查看完整回答
反對 回復 2022-01-19
  • 2 回答
  • 0 關注
  • 215 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號