Thanks for replying. The aim was to retrieve a PendingIntent and to modify it. There would be several PendingIntents that had been registered for multiple alarms. They are also stored in a db to register upon app startup.
register PendingIntent_i for Alarm_i. [i=0..n] use the data part of the PendingIntent to identify the alarm number (any other way to do this?). retrieve PendingIntent_i from AlarmManager, verify that it is the correct one, modify some characteristic of it e.g. change text to be displayed or alert time. Thank you for pointing out that the Receiver will not be called when the alarm goes off, if the app is not running - I did not realize that. I was using a BroadcastReceiver because I wanted to append the current time to a TextView each time the alert happens - to see that the alarm time was indeed modified correctly for that alarm. Also, getActivity() specifies you use FLAG_ACTIVITY_NEW_TASK - seemed better to reuse the activity and wasteful to start a new task for repeating alarms and in this toy program. Why is there no registerReceiver(BroadcastReceiver) call? The API call requires an IntentFilter also. Is the API not in sync with what can be specified through the manifest? (IntentFilter not mandatory there). I shall look at the android source for the Desktop clock you had pointed me to in another thread. Anyway, I am not able to get the alert happen with explicitly specifying the component. ========= <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.iovercomer" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/ app_name" android:debuggable="true"> <activity android:name=".TestIntentResolution" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name="com.iovercomer.TestIntentResolution.MyAlarmReceiver"></ receiver> </application> </manifest> ========== package com.iovercomer; import java.util.Calendar; import java.util.Date; import android.app.Activity; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.SystemClock; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class TestIntentResolution extends Activity { public static final String ALERT_ME_ACTION = "com.iovercomer.TestIntentResolution.alertMe"; AlarmManager am; PendingIntent mPendingIntent; String uriBase = "content://com.iovercomer/alerts/"; Intent alertIntent; int alarmNumber = 99; protected int requestCode = 23; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button startButton = (Button) findViewById(R.id.start_alarm); startButton.setOnClickListener(mStartAlarmListener); am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alertIntent = new Intent(TestIntentResolution.this,TestIntentResolution.MyAlarmReceiver.class); } private OnClickListener mStartAlarmListener = new OnClickListener() { @Override public void onClick(View v) { Uri alert_i = Uri.parse(uriBase + alarmNumber); // comment out the following line to get the intent to resolve to the receiver alertIntent.setData(alert_i); int flags = PendingIntent.FLAG_UPDATE_CURRENT; mPendingIntent = PendingIntent.getBroadcast(TestIntentResolution.this, requestCode , alertIntent, flags); long firstTime = SystemClock.elapsedRealtime(); am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime + 10 * 1000, mPendingIntent); Toast.makeText(TestIntentResolution.this, "starting >>>" + "alarm " + alarmNumber, Toast.LENGTH_LONG).show(); } }; void alertMe(String time, String data) { String t = "alert! at " + time + " " + data + "\n"; Toast.makeText(getApplicationContext(), t, Toast.LENGTH_SHORT).show(); TextView tv = (TextView) findViewById(R.id.myginew); tv.setText(t); } public class MyAlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Date dt = Calendar.getInstance().getTime(); intent.getAction(); intent.getType(); Uri d = intent.getData(); String frag = (d == null ? "":d.getLastPathSegment()); alertMe(dt.toString(), frag); } }; } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

