Tuesday 15 March 2011

Notification not received in Android 2.3 -



Notification not received in Android 2.3 -

i'm implementing notification service , have problems receive messages in android 2.3. receive messages in versions 4.0 , newer not in 2.3. in logcat appears next errors:

could not find class 'com.google.android.gms.ads.internal.b.c', referenced method com.google.android.gms.ads.internal.n.e.a . . not find class 'android.app.notification$builder', referenced method com.google.android.gms.common.l.a

what problem? method send notification:

private void sendnotification(string msg) { mainactivity.notificationclicked = true; int icon = r.drawable.ic_launcher; long when = system.currenttimemillis(); notificationmanager notificationmanager = (notificationmanager) .getsystemservice(context.notification_service); string strmessage = loadpreferences(); string newmessage = ""; if (!strmessage.isempty()) newmessage = strmessage + "<br>" + msg; else newmessage = msg; remoteviews contentview = new remoteviews(getpackagename(), r.layout.custom_notification_layout); contentview.setimageviewresource(r.id.image, r.drawable.ic_launcher); contentview.settextviewtext(r.id.text, html.fromhtml(newmessage)); notification notification = new notification(icon, html.fromhtml(msg), when); notification.contentview = contentview; string title = this.getstring(r.string.app_name); activitymanager = (activitymanager) getsystemservice(activity_service); list < activitymanager.runningtaskinfo > taskinfo = am.getrunningtasks(1); log.d("current task :", "current activity ::" + taskinfo.get(0).topactivity.getclass().getsimplename()); componentname componentinfo = taskinfo.get(0).topactivity; intent notificationintent; if(!componentinfo.getpackagename().equalsignorecase("com.example.myapp")){ notificationintent = new intent(getapplicationcontext(), firstactivity.class); } else { notificationintent = new intent(getapplicationcontext(), mainactivity.class); notificationintent.putextra("login", true); } notificationintent.putextra("message", html.fromhtml(msg)); oldmessage = newmessage; savepreferences(getapplicationcontext(), oldmessage); notificationintent.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top | intent.flag_activity_new_task); int notifyid = 1; pendingintent intent = pendingintent.getactivity(this, notifyid, notificationintent, pendingintent.flag_update_current); notification.setlatesteventinfo(this, title, msg, intent); notification.flags |= notification.flag_auto_cancel; notification.contentintent = intent; notificationmanager.notify(notifyid, notification); }

when send message receive in device android 4.2 illustration not in devices android 2.3. i'm debugging app android 2.3 , have set breakpoint in method onhandleintent of intentservice never comes. think errors appears in logcat.

how can solve problem devices android 2.3?

thanks in advance.

i alter notification notificationcompat:

notificationcompat.builder mbuilder = new notificationcompat.builder(this); mbuilder.setcontentintent(intent); notification notification = mbuilder.build(); notification.contentview = contentview; notificationmanager.notify(notifyid, notification);

but problem persist, in logcat appears same error

try code. i've used in project , runs good. receiveractivity activity open onclick, can remember, i'm not 100% sure of it.

public static void shownotification ( context context, class receiveractivityclass, string title, string text, int icon ) { intent intent = new intent( context, receiveractivityclass ); pendingintent pendingintent = pendingintent.getactivity( context, 0, intent, 0 ); // build notification notification notification = new notification.builder( context ) .setcontenttitle( title ) .setcontenttext( text ) .setsmallicon( icon ) .setcontentintent( pendingintent ) .setautocancel( true ) .getnotification(); notificationmanager notificationmanager = ( notificationmanager ) context.getsystemservice( context.notification_service ); notificationmanager.notify( 0, notification ); }

android android-notifications

No comments:

Post a Comment