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. filtering dialog items in onPrepareDialog()

My application has a ListView displaying some items that are
associated with different documents:

// arrays.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="select_doc_dialog_items">
        <item>doc type A</item>
        <item>doc type B</item>
        <item>doc type C</item>
        <item>doc type D</item>
    </string-array>
</resources>

The ListView implements an OnItemLongClickListener and displays the
available document types as follows:

        public boolean onItemLongClick(AdapterView<?> av, View v, int
position, long id) {
            mPositionActive = position;
            mListView.invalidate();  // TODO: increase efficiency by reducing
invalidate to one item

            if ((position%10) < 4) {
                Toast.makeText(this, "long click position " + position " has
docs",
                                Toast.LENGTH_SHORT).show();
            showDialog(DIALOG_DOCS_AVAILABLE);
            }
            else
                Toast.makeText(this, "long click position " + position + " has
no docs",
                                Toast.LENGTH_SHORT).show();

            return true;
        }

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DIALOG_DOCS_AVAILABLE:
            return new AlertDialog.Builder(this)
                .setTitle(R.string.select_doc_dialog)
                .setItems(R.array.select_doc_dialog_items, new
DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int
which) {

                        /* User clicked so do some stuff */
                        String[] items = getResources().getStringArray
(R.array.select_doc_dialog_items);
                        Toast.makeText(List15.this, "You selected: " + which
+ " , " + items[which],
                                        Toast.LENGTH_SHORT).show();
                    }
                })
                .create();
        }
        return null;
    }

    @Override
    protected void onPrepareDialog(int id, Dialog dialog) {
        super.onPrepareDialog(id, dialog);
        Toast.makeText(List15.this, "onPrepareDialog id: " + id,
Toast.LENGTH_SHORT).show();
    }

- - -

I would like to modify onPrepareDialog to filter the dialog to display
only the document types relevant for the long clicked item (like a
context menu except that some long clicks will perform a different
task: expand or collapse the hierarchy displayed in the custom
ListView).  For example, if an item is long clicked that is associated
with only document types A and B, I would like the dialog to avoid
displaying document types C and D as dialog items?   However, looking
at R.java, it is not clear to me what the id of an individual item in
the select_doc_dialog_items array would be.

Anyone have any tips on how to use onPrepareDialog() to filter
displayed dialog items?

Thanks and best regards,
Greg

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

2. I don't receive broadcasts

Hello!

I have started developing a tool, which should react on an outgoing call or 
sms and also to be started at boot time. The start at boot time does work 
properply, but I'm not able to receive the broadcasts for the outgoing calls.

Who can tell me, what is wrong with my code??

For this, I added two receivers in my manifest and implemented the broadcast-
receivers:
manifest.xml:
----------------------------------
<receiver 
        android:enabled="true" 
        android:name=".BootUpReceiver"  
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
        <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
</receiver>
<receiver 
        android:name=".TelephoneViewer"
        android:enabled="true"
        android:exported="true"
        android:permission="">
        <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        <action android:name="android.intent.action.PHONE_STATE" />
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
</receiver>
----------------------------------

TelephoneViewer.java:
----------------------------------
public class TelephoneViewer extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
        Log.d(this.getClass().getSimpleName(), "Telephoneviewer.onReceive()");
        Toast.makeText(context,"TelephoneViewer.onReceive()", 
Toast.LENGTH_SHORT).show();
}
----------------------------------

Thank you very much for your support!

Best regards,
Frank

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

3. How to use custom layout for Menu?

4. inter-activity animations

5. Memory leak - heap size (again)

6. PARC implicit authentication group looking for users!

7. Setting tab heights