我爲我的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);
}
請發佈您的代碼 –
我剛剛發佈我的代碼。 –