simple demo multiple alarms

by guruk » Sun, 26 Apr 2009 18:12:28 GMT


Sponsored Links
 Hi, i like to create multiple alarms, but i does not work. how to set
and how to request in my receiver what alarm intent came activated

in my alarm.java i call this function like: setalarm(5); setalarm(10)
(it works but only remember the last)


 public void setalarm(int delay)
    {
         Intent intent = new Intent(alarm.this, alarmreceiver.class);
         PendingIntent sender = PendingIntent.getBroadcast(alarm.this,
0, intent, 0);
         intent.setData((Uri.parse("custom://"+delay)));  << i heared
about this would make individual alarms.. but does not work

         Calendar calendar = Calendar.getInstance();
         calendar.setTimeInMillis(System.currentTimeMillis());
         calendar.add(Calendar.SECOND, delay);

         intent.putExtra("avr", ""+delay);   //i tried to set my data
here to read later, but also does not work


         AlarmManager am = (AlarmManager)getSystemService
(ALARM_SERVICE);
         am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
sender);

         //Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show
();

    }

---- my alarmreceiver.java

public class alarmreceiver extends BroadcastReceiver
{
        NotificationManager mNM;
        @Override
 public void onReceive(Context context, Intent intent)
 {
                Uri ursistr = intent.getData();
                String intentstr = intent.getStringExtra("avr");  //does not 
get the
saved intentextra?!

        Toast.makeText(context, "GOT IT :"+intentstr+" "+ursistr,
Toast.LENGTH_SHORT).show();

 }

greets
chris


--~--~---------~--~----~------------~-------~--~----~



simple demo multiple alarms

by Ashok Jeevan » Mon, 27 Apr 2009 16:34:59 GMT


 Hi,Try using

am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+(delay * 1000)
, sender);

This will set the alarms according to the delay that you specify.







--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


simple demo multiple alarms

by guruk » Thu, 30 Apr 2009 02:36:00 GMT


 thanks...
finaly the calendar add.. do the same.

but that does not answer my question, how to initiate MULTIPLE
Alarms.. and especialy
how o read them in me broadcast receiver and how to know what alarm
comes initiated.

thanks
chris





--~--~---------~--~----~------------~-------~--~----~



simple demo multiple alarms

by Jeff Sharkey » Thu, 30 Apr 2009 11:22:45 GMT


 ight, this is because PendingIntents only keep track of one set of
extras for a given action+data+category+component combination. That
is to say, it ignores extras when comparing PendingIntents.

Because your second PendingIntent matches the first one, the system
recycles the first one.

Depending on the desired behavior, you could use FLAG_CANCEL_CURRENT
to wipe the old PendingIntent and replace it with a new one containing
the updated extras. Or, if you need multiple events, you could use
the data Uri to hold the extra information. (So something like
"custom://avr/myvalue" might work.)

j

On Wed, Apr 29, 2009 at 11:35 AM, guruk <ilovesi...@gmail.com> wrote:



--
Jeff Sharkey
jshar...@google.com

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. MAC address?

I'm still on my unique device ID kick.

In Java 6, NetworkInterface has getHardwareAddress() to return the MAC 
address. According to the docs, Android 1.0r1 lacks this method.

Anyone know another way to get the MAC address of an Android device?

Thanks in advance!

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com

Android Training on the Ranch! -- Mar 16-20, 2009
http://www.bignerdranch.com/schedule.shtml

--~--~---------~--~----~------------~-------~--~----~

2. no icon in menu after install apk files to /data/app in target board

api_demo and snake icon is in menu after abd install in emulator. but
no icon in target.
emulator:
D:\andriod\android-sdk-windows-1.0_r1\tools>adb.exe shell
# cd /data/app
cd /data/app
# ls
ls
com.example.android.apis.apk
com.example.android.snake.apk
#

Target:
# cd /data/app
# ls
com.example.android.apis.apk
snake.apk
#

any idea?

Thanks
Sam

--~--~---------~--~----~------------~-------~--~----~

3. Trying to download Android source - repo sync connection reset

4. MediaPlayer output monochrome video

5. About Android Mobile Programming

6. Getting source under Windows (from web interface).

7. Now the source is released what steps do we need to take to port to other hardware?