I don't know if it is possible to do this in a notification window but I
guess theoretically it could work. The way I implemented my one of my
widgets was as follows:
- First, I used ImageVIews instead of Buttons but I'm not sure that
matters too much
- I assigned each ImageView a custom action that I defined in my
service's intent filter
- The pending intent that I set on each ImageView started the same
service but the intent for each view had a different action
- When I started the service I looked at the action and did work based on
that action
Below are some code snippets that should help you get started. Obviously
you will have to modify them to suit your needs...
*Here is some code that I used to create the onClick pending intent for one
of my views:*
newIntent = new Intent(context, RunningAppWgtUpdateService.class);
newIntent.setAction("com.magouyaware.appswipe.WgtUpdateService.ACTION_CLICK_0");
ViewHolder.s_curView.setOnClickPendingIntent(R.id.wgt_app_icon_0,
PendingIntent.getService(this, 0, newIntent, 0));
*Here is the manifest definition for my service, along with its intent
filter:
*<service
android:name=".services.RunningAppWgtUpdateService"
android:label="@string/app_widget_update_service"
>
<intent-filter>
<action android:name=".WgtUpdateService.ACTION_NEXT" />
<action android:name=".WgtUpdateService.ACTION_PREV" />
<action android:name=".WgtUpdateService.ACTION_CLICK_0" />
<action android:name=".WgtUpdateService.ACTION_CLICK_1" />
<action android:name=".WgtUpdateService.ACTION_CLICK_2" />
<action android:name=".WgtUpdateService.ACTION_CLICK_3" />
<action android:name=".WgtUpdateService.ACTION_REFRESH" />
<action android:name=".WgtUpdateService.ACTION_REFRESH_NO_UPDATE" />
<action android:name=".WgtUpdateService.ACTION_CLOSE_ALL" />
<action android:name=".WgtUpdateService.ACTION_MODE_OPEN" />
<action android:name=".WgtUpdateService.ACTION_MODE_CLOSE" />
<action android:name=".WgtUpdateService.ACTION_NO_OP" />
</intent-filter>
</service>*
*
Hope that helps some...
On Tue, Mar 1, 2011 at 2:28 AM, Hitendrasinh Gohil <
[email protected]> wrote:
> hi,
> i am able to add remoteview to notification window.from this link.
> http://developer.android.com/guide/topics/ui/notifiers/notifications.html
>
> now i have added four buttons and i want to handle the click events of
> buttons from notification window.
> and below is my code.i am able to add view to notification window but
> i dont know how to define click events for buttons.
> like its in native music player of android,when we exit the player
> screen player running in background and we can do next,previous,play/
> pause from notification window.
>
> Notification notification = new Notification(
> R.drawable.playbackstart, Trackname,0);
>
> RemoteViews contentView=new
> RemoteViews(getPackageName(),R.layout.demo);
> notification.contentView = contentView;
>
>
> notification.flags |= Notification.FLAG_NO_CLEAR;
> notification.flags |= Notification.FLAG_ONGOING_EVENT;
>
> Intent intent = new Intent(getApplicationContext(),
> Main.class);
> PendingIntent contentIntent =
> PendingIntent.getActivity(this, 0,
> intent, Intent.FLAG_ACTIVITY_NEW_TASK);
>
> contentView.setOnClickPendingIntent(R.id.demoButton01,contentIntent);
>
> contentView.setOnClickPendingIntent(R.id.demoButton02,contentIntent);
>
> notification.contentIntent=contentIntent;
> /* notification.setLatestEventInfo(this, Trackname,
> Artistname,
> pendingIntent);
>
> nm.notify(NOTIFY_ID, notification);*/
> nm.notify(NOTIFY_ID, notification);
>
>
> is there anyone to help me?
>
> --
> 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
--
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