gpt4 book ai didi

android - 如何在我的应用程序运行时将我的应用程序图标添加到状态栏中?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:00:40 25 4
gpt4 key购买 nike

我尝试使用 Notification.BuilderNotification 类。

我试过使用这段代码:

Notification notification = new Notification.Builder(this).build();
notification.icon = R.drawable.ic_launcher;
notification.notify();

但是好像没什么用。

我只想在电池图标、wifi 图标和 3g 图标旁边添加我的应用程序图标。有什么方法可以做到这一点吗?感谢您的帮助。

最佳答案

在完成对通知的描述后,您必须调用方法 build()。查看Android reference举个例子。

基本上,您必须将代码更改为以下内容:

Context context = getApplicationContext();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context )
.setSmallIcon(R.drawable.ic_launcher);

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

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

注意:此代码将只允许在通知栏中显示您的图标。如果你想让它一直存在,你将不得不使用 FLAG_ONGOING_EVENT

关于android - 如何在我的应用程序运行时将我的应用程序图标添加到状态栏中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16887512/

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