Sunday, December 26, 2010

[android-developers] Re: Buttons supported in notification expanded view?

I am having same problem. Clicks on individual buttons work on HTC HD2
with Android 2.2 but not on mytouch 3g with Android 2.2.1.

To solve the problem of launching just one intent - use a dummy class
for default pending intent and use your required class for button's
pending intent.

On Dec 4, 6:26 pm, David Huang <huang...@gmail.com> wrote:
> 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 <rerdav...@gmail.com> 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,cancelI ntent);
>
> >                        mNotificationManager.notify(notificationID,
> > notification);
>
> > On Dec 4, 3:50 pm, Paul Turchenko <paul.turche...@gmail.com> wrote:
> > > Can you post a code you use to create pending intent?
>
> > > On Dec 3, 1:18 am, CrazyH <huang...@gmail.com> 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 android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscribe@googlegroups.com<android-developers%2Bunsubs cribe@googlegroups.com>
> > 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment