My icons are having names icon_1
, icon_2
, icon_3
and so on. And I want to change the icon in the notification dynamically according to the input. The input is a number ranging from 1 to 100.
if the input is 1 then icon_1
should be shown, if input is 2 then icon_2
will be shown and so on. Is it possible to set the icon in one line or we are forced to use switch case statement? The example with the code I am pasting here to better understand. Switch case statement definitely will help out but only want to know if it is possible to write in one line to save 100 lines of code.
The following lines of code may not work. But just for understanding the things, I have used.
Input is a number in the variable name of num
.
Intent intent = new Intent(this, NotificationReceiver.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification n = new Notification.Builder(this)
.setContentText("Subject")
.setSmallIcon(R.drawable.icon_+"num") //Here is the doubt..How can we modify this line to work
.setContentIntent(pIntent)
.setAutoCancel(true)
.build();
NotificationManager notificationManager=NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, n);