Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Catch Events on Notification (Long Press)

The standard short click on a Notification fires the PendingIntent held in it.

Is it possible to catch other events?

The requirement is to catch a Long Press.

like image 784
Seb Avatar asked Aug 09 '11 22:08

Seb


1 Answers

Although you can create custom Notification-Views with NotificationCompat and RemoteViews you have no means to manipulate underlying click-behavior. The only options you have got is to change some parameters for a handfull of ViewTypes:

  • Buttons: setOnClickPendingIntent() to change button-intents
  • TextViews: setTextViewText() textview-contents
  • RemoteViews: addView() sounds great but works only to insert nested RemoteViews
  • ListViews: setOnClickFillInIntent() Apply intents for ListViews
  • ImageViews: setImageViewBitmap() change the picture for an ImageView
  • and a few more..

So to answer your Question: No, with the most current Google API (api lvl 17 - 14.01.2013) you can not insert a onLongClickListener into any of the view-elements within a notification.

Why is this so?

RemoteView is only a boiled down, simpler derivate of a View. It is not even related to View (RemoteView extends Object) therefore does not provide all the options you would have in a real View (View.setOnLongClickListener()) .

What are RemoteViews?:

A RemoteView can be executed by another process with the same permissions as the original application(that is why they are called Remote Views). This way widgets and notifications run with the permissions of its defining application.

From ICS on, long press on a notification triggers the "App Info" option, so you can see which app is sending it (useful to identify spamming apps) Also, from JellyBean on, you have enriched notifications that allow you to do many things, including more than one action, probably you can solve your problem with that.

Shalafi

If you want more insight I recommend these articles:

  • http://www.vogella.com/articles/AndroidWidgets/article.html especially chapter 3.2 where you can find more valuable information.
  • http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
like image 144
AndacAydin Avatar answered Nov 15 '22 19:11

AndacAydin