簡體   English   中英

如何修復Android狀態欄中的圖標

[英]How to fix icon in Android status bar

我下面有在Android狀態欄上創建圖標的代碼。

Context context = getApplicationContext();
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.ic_launcher)
    .setContentTitle(getString(R.string.app_name))
    .setContentText("Live Tracking");

Intent intent = new Intent( context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent pIntent = PendingIntent.getActivity(context, mID , intent, 0);
builder.setContentIntent(pIntent);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

Notification notif = builder.build();
mNotificationManager.notify(mID, notif);

當用戶按下“清除所有通知”按鈕時,是否有辦法防止圖標被刪除?

非常感謝您的幫助。 最好的問候,文森特。

setOngoing(true)添加到通知構建器。 這會保留該通知,因此您必須確保自己刪除它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM