我想通過在我的HelloWorldPlugin.java上擴展CordovaPlugin來使用cordovaplugin發送本地通知..但是看起來我的本地通知代碼不起作用。如果我把這段代碼放在自動生成的擴展CordovaActivity的AndroidCordova中,它就可以工作。這裏是下面的代碼在Hybrid-Native Android eclipse中使用CordovaPlugin的本地通知
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;
它返回2錯誤。首先它說「構造函數Notification.Builder(HelloWorldPlugin)未定義」,NOTIFICATION_SERVICE不能解析爲變量。 另外我在getActivity之後在零件上添加了上下文上下文和使用的上下文,我在擴展CordovaActivity的另一個插件上使用了這個。我需要幫助,請即時困在這裏現在4天..
謝謝你所有的努力。對不起,但我一直在使用eclipse幾天,我仍然是新東西。這是擴展CordovaPlugin?因爲我的老闆需要(我是一個19y/o ojt)我使用cordovaplugin ..還有什麼我放在yourfunctionreturncontexthere(); .. 現在嘗試你的代碼..非常感謝 – Ziddorino 2014-12-04 02:20:36
是的,它擴展了CordovaPlugin – 2014-12-04 03:26:32
你的functionreturncontext是僞函數,用於從你的應用程序獲取上下文,你可以忽略這個函數,只使用conte xt正如你之前使用的那樣。 – 2014-12-04 03:32:52