I want my app to be able to pick a random item from this string array:
<string-array name="quote_list">
<item>Quote 1 </item>
<item>Quote 2 </item>
<item>Quote 3</item> </string-array>
And send the item off in a notification to the user. (Will be at a time chosen by user, using alarmmanager)
I believe I can generate a random item using the following method. How to get a random value from a string array in android?
Would I start off with something like this?
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText(String randomStr);
I still don't know really how I would go about placing a random item into a notification. Is it also possible to make it so the items the app chooses do not repeat?
Many Thanks,
-Mike
First get the random value from the string array (like the link you mentioned):
Then use
NotificationManager
to showrandomStr
to user: