Android Phonegap GCM onNotification返回结果:确定
我正在使用phonegap 我的问题是我在实际设备中收到了Android Phonegap GCM onNotification返回结果:确定,android,cordova,phonegap-plugins,phonegap-pushplugin,Android,Cordova,Phonegap Plugins,Phonegap Pushplugin,我正在使用phonegap 我的问题是我在实际设备中收到了onNotification功能警报消息“Result:Ok”,我也进行了检查 My config.xml <?xml version='1.0' encoding='utf-8'?> <widget id="com.xxxxxxxxxxx.xxxxxxxxxxxx" version="6.2" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap
onNotification
功能警报消息“Result:Ok”,我也进行了检查
My config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.xxxxxxxxxxx.xxxxxxxxxxxx" version="6.2" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>xxxxxxxx</name>
<description>
The #1 Mobile App to Earn Money on xxxxxx .
</description>
<author email="xxxxxx" href="http://xxxxxx.com">
xxxxxx Team
</author>
<icon src="icon.png" />
<content src="index.html" />
<access origin="*" />
<feature name="PushPlugin">
<param name="android-package" value="com.plugin.gcm.PushPlugin" />
</feature>
<feature name="NetworkStatus">
<param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager" />
</feature>
<gap:plugin name="org.apache.cordova.InAppBrowser" />
<icon src="icon.png" />
<icon gap:platform="android" height="114" src="res/icon/android/icon-xxhdpi.png" width="114" />
<icon gap:platform="android" height="96" src="res/icon/android/icon-xhdpi.png" width="96" />
<icon gap:platform="android" height="72" src="res/icon/android/icon-hdpi.png" width="72" />
<icon gap:platform="android" height="48" src="res/icon/android/icon-mdpi.png" width="48" />
<icon gap:platform="android" height="36" src="res/icon/android/icon-ldpi.png" width="36" />
<icon gap:platform="ios" src="res/icon/ios/icon.png" />
<engine name="android" spec="^4.0.0" />
</widget>
如何从gcm获取注册id。这里是使用gcm进行phonegap通知的一个很好的示例,效果很好
devicerady
事件是否正确定义并触发注意:如果您得到
OK
响应,则表示插件工作正常,没有任何错误。您没有获得注册ID的原因可能是表面原因。java到javascript调用中存在问题。在CordovaWebView中,sendJavascript方法已被弃用。因此,从java调用javascript可以使用任何其他方法。
window.plugins.pushNotification.register(successHandler, errorHandler, {
ecb : 'onNotificationGCM',
senderID : 'xxxxxxxxxxxxxx'// Google Project ID.
});
// Method to handle device registration for Android.
var onNotificationGCM = function(e) {
alert(e.event);
if('registered' === e.event) {
// Successfully registered device.
alert(e.regid);
}
else if('error' === e.event) {
// Failed to register device.
alert(e.msg);
}
else if('message' === e.event) {
//mesage recived
alert(e.payload.message);
}
};
// result contains any message sent from the plugin call
function successHandler (result) {
alert('result = ' + result);
}
// result contains any error description text returned from the plugin call
function errorHandler (error) {
alert('error = ' + error);
}