My code is not that much different than edrowland's
// Set the contentIntent of notification
Intent defaultIntent = new Intent(context, DoNothing.class);
defaultIntent .setAction("Default");
PendingIntent pendingDefaultIntent = PendingIntent.getActivity(context,
0, defaultIntent , 0);
notification.contentIntent = pendingDefaultIntent
// Set remoteview and button intent
notification.flags |= Notification.FLAG_NO_CLEAR
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notificationView = new RemoteViews(context.getPackageName(),
R.layout.notification_layout);
activityIntent = new Intent(context, Launcher.class);
activityIntent.setAction("Launch"); // Used to make each launch intent
unique
pendingLaunchIntent = PendingIntent.getActivity(context, 0, activityIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
notificationView.setOnClickPendingIntent(R.id.button_1,
pendingLaunchIntent);
On Sat, Dec 4, 2010 at 2:14 PM, edrowland <[email protected]> wrote:
> I have the same problem on Galaxy tab. Currently both intents go to
> the same place (since having a cancel button is better than not having
> one,even if the cancel intent doesn't fire).
>
> Under no circumstance does the the intent for the cancel button fire,
> on a Galaxy Tab. Not setting a contentIntent is not an option. The
> APIs throw invalid parameter exceptions if I pass null for a
> contentIntent. (I've try activity and service intents. Neither work
> for the cancel button; both work for the contentIntent).
>
> If this actually worked, the cancel button would be configured to
> cancel, without prompting for Yes/no.
>
> Context context = getApplicationContext(); //
> application
> Context
> Intent notificationIntent = new Intent(context,
> CancelDownloadActivity.class);
> notificationIntent.setAction("CANCEL_BUTTON");
>
> cancelIntent =
> PendingIntent.getActivity(CopyService.this, 0,
> notificationIntent,0);
>
> Intent intent2 = new Intent(context,
> CancelDownloadActivity.class);
> intent2.setAction("CANCEL");
> contentIntent =
> PendingIntent.getActivity(CopyService.this,
> 0,intent2, 0);
>
> // configure the notification
> notification = new
> Notification(R.drawable.ics_download,
> "Downloading songs...", System.currentTimeMillis());
> notification.flags = notification.flags |
> Notification.FLAG_ONGOING_EVENT;
> String packageName =
> CopyService.this.getApplicationContext().getPackageName();
> notification.contentView = new
> RemoteViews(packageName,
> R.layout.download_progress);
> notification.contentIntent = contentIntent;
>
> notification.contentView.setImageViewResource(R.id.status_icon,
> R.drawable.ics_download);
>
> notification.contentView.setTextViewText(R.id.status_text,
> "Downloading...");
>
> notification.contentView.setProgressBar(R.id.status_progress, 100,
> 0, false);
>
>
> notification.contentView.setOnClickPendingIntent(R.id.status_cancel,cancelIntent);
>
> mNotificationManager.notify(notificationID,
> notification);
>
>
> On Dec 4, 3:50 pm, Paul Turchenko <[email protected]> wrote:
> > Can you post a code you use to create pending intent?
> >
> > On Dec 3, 1:18 am, CrazyH <[email protected]> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Hi,
> >
> > > I am trying to get buttons to work in notification expanded view. The
> > > goal is to use the buttons to launch activities from the notification
> > > view. Is this even supported? Here is a very simple outline with
> > > irrelevant details omitted:
> >
> > > 1. Create a RemoteView object using a layout with some ImageButtons.
> > > 2. Create pending intent for each button and set them using
> > > RemoteView.setOnClickPendingIntent(...)
> > > 3. Create a Notification object and set it's contentView as the
> > > RemoteView created in step 1.
> > > 4. Set Notification object's contentIntent.
> > > 5. Send the Notification.
> >
> > > This works beautifully on my Droid X. I can click on each button and
> > > launch it's associated activity successfully.
> >
> > > This works on my pal's Evo 4G as well, except that it launches the
> > > button's intent plus the notification's content intent. So two
> > > intents launched. But I can deal with that.
> >
> > > This also works on HTC Incredible.
> >
> > > Unfortunately, it doesn't work on most other phones: Vibrant, Hero,
> > > Vision, WildFire, MIleStone, Droid 1. These are the ones I know so
> > > far based on user feedback. On these phones, only the notification
> > > contentIntent is being launched. It appears the button's click events
> > > aren't being captured/detected.
> >
> > > I am at my wit's end trying to work around this. I am beginning to
> > > think it's impossible, but it works on some phones! Any suggestion/
> > > help is appreciated.
> >
> > > Thanks!
> > > .
>
> --
> 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
--
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