i looking way able retrieve contenttext notification object. following:
notificaioncompat.builder builder; notification existing; builder.setcontenttext(existing.contenttext); i have discovered can find , retrieve tickertext. following code already, example:
charsquence tickertext; tickertext = existing.tickertext; please can me figure out how solve problem?
thanks,
isaac
the best way using notificationlistenerservice. introduced in android 4.3 , considerably improved lots of new features in android 4.4. should use it.
how use
step 1
you first need extend notificationlistenerservice class , implement methods.
public class simplekitkatnotificationlistener extends notificationlistenerservice { @override public void onnotificationposted(statusbarnotification sbn) { //.............. } @override public void onnotificationremoved(statusbarnotification sbn) { //.............. } } step 2
then must declare service in manifest file bind_notification_listener_service permission , include intent filter service_interface action.
<service android:name="it.gmariotti.android.examples. notificationlistener.simplekitkatnotificationlistener" android:label="@string/service_name" android:debuggable="true" android:permission="android.permission.bind_notification_listener_service" > <intent-filter> <action android:name="android.service. notification.notificationlistenerservice" ></action> </intent-filter> </service> step 3
you must authorize user. can find in settings -> security -> notification access
intent intent = new intent("android.settings.action_notification_listener_settings"); startactivity(intent); step 4
use extras field information want to,
notification mnotification=sbn.getnotification(); bundle extras = mnotification.extras; you can lot of info class,
/** * {@link #extras} key: title of notification, * supplied {@link builder#setcontenttitle(charsequence)}. */ public static final string extra_title = "android.title"; /** * {@link #extras} key: main text payload, supplied * {@link builder#setcontenttext(charsequence)}. */ public static final string extra_text = "android.text"; /** * {@link #extras} key: third line of text, supplied * {@link builder#setsubtext(charsequence)}. */ public static final string extra_sub_text = "android.subtext"; /** * {@link #extras} key: bitmap used instead of small icon when showing * notification payload, * supplied {@link builder#setlargeicon(android.graphics.bitmap)}. */ public static final string extra_large_icon = "android.largeicon"; step 5
you can data this,
string notificationtitle = extras.getstring(notification.extra_title); int notificationicon = extras.getint(notification.extra_small_icon); bitmap notificationlargeicon = ((bitmap) extras.getparcelable(notification.extra_large_icon)); charsequence notificationtext = extras.getcharsequence(notification.extra_text); charsequence notificationsubtext = extras.getcharsequence(notification.extra_sub_text);
Comments
Post a Comment