I'm trying to add the Status Bar Notification Plugin for Cordova to my Android App, but I get an error with it's code.
Here's the problematic code:
Notification noti = new Notification.Builder(context)
.setContentTitle(contentTitle)
.setContentText(contentText)
.setSmallIcon(icon)
.build();
The error is on the .build()
, Eclipse tells me:
"The method build() is undefined for the type Notification.Builder"
I am having the same issue. It looks like a mismatch the sdk versions and now depreciated methods.
getNotification() is the method to call since API 11 build() was added in API 16
if you are like me, you are using a version < 16, so use .getNotification() instead.
Im not going to worry about API 16 right now but I bet if I download 16 and set my target to such, build() will work.
Let me know if it works for you.
For me .getNotification() didn't resolve the problem, because I need a solution for API 10 and higher.
I found a way to deal with it. If someone else has the same issue, I recommend to do this :
1) Go through instructions for StatusBarNotification (click)
2) Modify StatusBarNotification.java
private Notification noti;
private PendingIntent contentIntent;
Comment or delete:
import android.app.Notification.Builder;
and
Notification noti = new Notification.Builder(context)
.setContentTitle(contentTitle)
.setContentText(contentText)
.setSmallIcon(icon)
.build();
Instead of this part, paste:
noti = new Notification(android.R.drawable.btn_star_big_on, contentText, System.currentTimeMillis() ); noti.flags = Notification.FLAG_AUTO_CANCEL; Intent notificationIntent = new Intent(context, !yourMainActivityClass!.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent = notificationIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); noti.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
Add calling method in index.html For tests you can make JQM button with
onclick='window.plugins.statusBarNotification.notify("Put your title here", "Put your message here");return false;'
I know that this solution is using depreciated methods, but I spent a lof of hours to make it works and I didn't see another solution for API 10. If somebody has better idea, share with me ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With