alternating strings in Notification

Put your problem here if it does not fit any of the other categories.

alternating strings in Notification

Postby la3bna » Wed Sep 14, 2011 10:25 am

Hi

I would like to have three strings that should alternate in my notification.

The notification is triggered by a broadcast receiver that starts my notification service.
I would like the charsequence to alter between three ( or more) in a way that for each alarm trigger the text would change.

The user sets the string for the first notification but after that it would rotate between text1, text2, text3. and start over again when it comes to the last..

Is this possible?
la3bna
Experienced Developer
Experienced Developer
 
Posts: 72
Joined: Wed Mar 30, 2011 5:49 am
Location: Stavern, Norway

Top

Re: alternating strings in Notification

Postby la3bna » Wed Sep 14, 2011 6:30 pm

This is what I have in code so far.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void showNotification() {
  2.                
  3.        
  4.         String papp      =      "3";
  5.         String plast        =   "2";
  6.         String rest              =      "1";
  7.         SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
  8.         valgtavf = sharedPrefs.getString("hvilke_soppel", "1");
  9.          
  10.        
  11.         if (valgtavf.equals(papp))
  12.         {      
  13.         // In this sample, we'll use the same text for the ticker and the expanded notification
  14.                 text = getText(R.string.service_label1);
  15.                 SharedPreferences.Editor editor = sharedPrefs.edit();
  16.                 editor.putString("hvilke_soppel", "1");
  17.                 editor.commit();
  18.         }
  19.         if (valgtavf.equals(plast))
  20.         {
  21.                 text = getText(R.string.service_label2);
  22.                 SharedPreferences.Editor editor = sharedPrefs.edit();
  23.                 editor.putString("hvilke_soppel", "3");
  24.                 editor.commit();
  25.         }
  26.         if (valgtavf.equals(rest))
  27.         {
  28.                 text = getText(R.string.service_label3);
  29.                 SharedPreferences.Editor editor = sharedPrefs.edit();
  30.                 editor.putString("hvilke_soppel", "2");
  31.                 editor.commit();
  32.         }
  33.      
  34.         Notification notification = new Notification(R.drawable.notification, text,
  35.                 System.currentTimeMillis());
  36.    
  37.         PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
  38.                 new Intent(this, Main.class), 0);
  39.  
  40.        notification.setLatestEventInfo(this, getText(R.string.service_started),
  41.                        text, contentIntent);
  42.  
  43.         nm.notify(R.string.notify, notification);
  44.     }
  45.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4




or will this work?
la3bna
Experienced Developer
Experienced Developer
 
Posts: 72
Joined: Wed Mar 30, 2011 5:49 am
Location: Stavern, Norway

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 9 guests