我想通过在我的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