cordova-plugin-local-notifications本地通知推送在cordova 5.0.0以上版本编译报错解决办法

添加本地推送插件cordova-plugin-local-notifications 0.8.1,在cordova 5.0.0以上版本编译报错

LocalNotification.java:495: error: cannot find symbol
webView.evaluateJavascript(js, null);
^
symbol: method evaluateJavascript(String,)
location: variable webView of type CordovaWebView
/ug/ug-app/platforms/android/src/de/appplant/cordova/plugin/localnotification/LocalNotification.java:492: error: cannot find symbol
webView.post(new Runnable(){
^
symbol: method post()
location: variable webView of type CordovaWebView
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors
FAILED


FAILURE: Build failed with an exception.

修改cordova-plugin-local-notifications中源代码LocalNotification.java:492

替换为
webView.getView().post(new Runnable(){
		  public void run(){
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			  webView.sendJavascript(js);
			} else {
			  webView.loadUrl("javascript:" + js);
			}
		  }
		});

同时在platforms\android\src\de\appplant\cordova\plugin\localnotification.java 进行修改替换,运行cordova build android顺利通过。
原因是cordova 5.0.0以上版本对evaluateJavascript不再支持,用sendJavascript进行替换。
 
 

你可能感兴趣的:(cordova)