I want to send local notifications using cordovaplugin by extending CordovaPlugin on my HelloWorldPlugin.java.. But it seems my code for local notifications doesnt work. If i put this piece of code in the auto-generated AndroidCordova that extends CordovaActivity it works. Here is the code below
public class HelloWorldPlugin extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
throws JSONException {
if (action.equals("sayHello")){
Context context //Added:
Intent intent = new Intent();
PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
Notification noti = new Notification.Builder(this)
.setTicker("Test Ticker Notification")
.setSmallIcon(R.drawable.icon)
.setContentTitle("Test Title Notification")
.setContentText("Test Content Notification")
.setContentIntent(pIntent).build();
noti.flags=Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
return true;
}
return false;
It is returning 2 errors. First one is it says "The constructor Notification.Builder(HelloWorldPlugin) is undefined" and NOTIFICATION_SERVICE cannot be resolved to a variable. Also i added the Context context and used context on the part after getActivity, i used this on my other plugin that extends CordovaActivity. I need help please im stuck here for 4 days now..