gpt4 book ai didi

安卓通知图标

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:37:47 28 4
gpt4 key购买 nike

Android 开发新手。我想知道是否有可能以编程方式绘制一个图标以放入通知栏?如果我们希望图标显示电池电量等动态文本怎么办?

如果有人有代码示例那就太好了。谢谢。

最佳答案

调用我们想要通知的函数。

 public void notification(String name) {

final int id = 2;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.fbc;
CharSequence tickerText = "facebook";
long when = System.currentTimeMillis();

Notification checkin_notification = new Notification(icon, tickerText,
when);
Context context = getApplicationContext();
CharSequence contentTitle = "You are name is"+ name;
CharSequence contentText = "Do You want to Check-in ?? ";

Intent notificationIntent = new Intent(context, LoginTab.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
checkin_notification.setLatestEventInfo(context, contentTitle,
contentText, contentIntent);
checkin_notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(id, checkin_notification);

}

关于安卓通知图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4102943/

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