Skip to content
Advertisement

Android notification with RemoteViews – having activity associated with RemoteViews layout

I’ve been researching on how to create custom-layout notification using RemoteView.

So far, I am able to create a notification with contentView and bigContentView pointing to a RemoteView with a custom layout xml. However, what does not happen, is to have Activity (associated with custom layout) started when this RemoteView is created.

I’ve double checked and in my layout xml, it appears to have correct Activity class name:

JavaScript

In manifest file, right after main application main activity, notification activity is also added:

JavaScript

I would expect when notification uses RemoteView for its content, that this RemoteView will launch activity that is attached to its layout definition. However it appears not.

Here is how I create a notification in main application Activity:

JavaScript

LLMNotificationActivity activity class is defined as usual:

JavaScript

Can anyone point to me what I am missing or if I have misunderstood what RemoteView can do? My understanding is that RemoteView should, once created, invoke activity associated with its layout. Or – is there some API I’ve missed that explicitly can set intent of the RemoteView?

What I have found so far are only setting content Intent which basically just launches an Activity once user touches notification. What I’m looking for is to handle touches to some of UI elements inside custom-layout notification, not to launch an Activity regardless where the user clicks on notification surface.

For example, if I have 3 icons (i.e. ImageView) in a RemoteView which notification uses, I’d like to be able to handle touch on each one of them. I can’t imagine this wouldn’t be possible as if it’s not, what’s the point of having RemoteView in notification?

Advertisement

Answer

You have to associate the activity thought setOnClickPendingIntent to launch the activity from remote view as below…You can set any of the layout id in the RemoteView to click.

JavaScript

provide an +id/layout_id to the RelativeLayout your using.

If you have to launch the activity when user click on the notification, then you have to use PendingIntent as….

JavaScript

For 3 buttons , You have to use create a custom RemoteView and use PendingIntent. some thing as below…

Here is the custom remote view i am using for one of my media player app. it has three button to handler click.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement