gpt4 book ai didi

android - 在通知图标中添加数字

转载 作者:行者123 更新时间:2023-11-30 00:45:57 27 4
gpt4 key购买 nike

我为我的 Android 应用程序实现了一个通知系统,我想知道是否有任何方法可以将小图标设置为数字/文本。因为在我的通知中我想在小图标字段中显示用户的新订单数量。无论如何,有没有办法在不涉及大量具有不同数字的不同图像并将它们组合起来生成任何数字的情况下做到这一点?

这是我的 pushNotification 方法:

public void PushNotification()
{
NotificationManager nm = (NotificationManager)getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(getApplicationContext());
Intent notificationIntent = new Intent(getApplicationContext(), MainScreen.class);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(),0,notificationIntent,0);

//set
builder.setContentIntent(contentIntent);
builder.setSmallIcon(R.drawable.chef_hat);
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.chef_hat);
builder.setLargeIcon(largeIcon);

builder.setContentText("Click here to open the app.");
//Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
//builder.setDefaults(Notification.DEFAULT_SOUND);

System.out.println("Subtraction: " + (auxiliar1 - auxiliar2));

if (auxiliar1 - auxiliar2 == 1) {
builder.setContentTitle("You have a new order!");
} else if ((auxiliar1 - auxiliar2) > 1){
builder.setContentTitle("You have " + (auxiliar1 - auxiliar2) + " new orders!");
} else {
builder.setContentTitle("You have a new order!");
}

auxiliar1 = 0;
auxiliar2 = TabLayoutScreenActivity.orderSizeFixed;

if(android.os.Build.VERSION.SDK_INT>=21) {
builder.setColor(Color.parseColor("#D8540D"));
}
builder.setAutoCancel(true);
//builder.setDefaults(Notification.DEFAULT_ALL);
long[] v = {500,1000};
builder.setVibrate(v);
if (PrefernceHelper.getString(MainScreen.this, Commons.Constants.NOTIFICATION_SOUD) == null) {
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(uri);
}
else {
builder.setSound(Uri.parse(PrefernceHelper.getString(MainScreen.this, Commons.Constants.NOTIFICATION_SOUD)));
}

Notification notification = builder.build();
nm.notify((int)System.currentTimeMillis(),notification);
}

最佳答案

我希望您问的是通知图标而不是启动器图标。

如果您询问通知图标,请转到此处 https://www.skoumal.com/en/android-how-draw-text-bitmap/

我确实建议将位图用作 setLargeIcon 方法的一部分,因为小图标用作应用程序的通知图标。

// notification icon
builder.setSmallIcon(R.drawable.ic_notification);

//you can use custom icon
Bitmap largeIcon = createMyCustomIconWithNumber();
builder.setLargeIcon(largeIcon);

如果您要询问有关启动器图标的信息,请转到此处。 https://github.com/leolin310148/ShortcutBadger

关于android - 在通知图标中添加数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41805535/

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