我已经集成了pushwoosh sdk,可以通过PhoneGap在Android上发送GCM推送通知。 我可以在我的设备上接收通知,但没有声音,没有振动,唤醒锁定,也没有LED。
您可以在此处找到我在AndroidManifest.xml上的权限
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
package="MY_PACKAGE_NAME" android:versionName="1.1" android:versionCode="5" android:hardwareAccelerated="true">
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="false"
android:resizeable="true"
android:anyDensity="true"
/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<permission
android:name="MY_PACKAGE_NAME.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission
android:name="MY_PACKAGE_NAME.permission.C2D_MESSAGE"/>
<uses-permission
android:name="com.google.android.c2dm.permission.RECEIVE"/>
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true">
<activity android:name="MyApp" android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:screenOrientation="portrait" android:launchMode="singleTop">
<intent-filter>
<action android:name="MY_PACKAGE_NAME.MESSAGE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.arellomobile.android.push.PushWebview"/>
<activity android:name="com.arellomobile.android.push.MessageActivity"/>
<activity android:name="com.arellomobile.android.push.PushHandlerActivity"/>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="MY_PACKAGE_NAME"/>
</intent-filter>
</receiver>
<service android:name="com.arellomobile.android.push.PushGCMIntentService"/>
</application>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/></manifest>
这是我的初始化函数:
function initPushwoosh() {
var pushNotification = window.plugins.pushNotification;
pushNotification.onDeviceReady();
//projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID"
pushNotification.registerDevice({ projectid: "MY_PROJECT_ID", appid : "MY_PUSHWOOSH_APP_ID" },
function(status) {
var pushToken = status;
console.warn('push token: ' + pushToken);
},
function(status) {
console.warn(JSON.stringify(['failed to register ', status]));
});
document.addEventListener('push-notification', function(event) {
var title = event.notification.title;
var userData = event.notification.userdata;
if(typeof(userData) != "undefined") {
console.warn('user data: ' + JSON.stringify(userData));
}
navigator.notification.alert(title);
pushNotification.stopGeoPushes();
});}
在这里,您可以找到pushwoosh的示例(我遵循):pushwoosh example
哪里错了?
谢谢, 丹尼尔
答案 0 :(得分:1)
你必须做一些Java来实现这一目标。
转到Android项目,找到位于PushNotifications
的{{1}}课程并查找此行:
/src/com/pushwoosh/plugin/pushnotifications/
然后添加以下行:
mPushManager = new PushManager(cordova.getActivity(),
params.getString("appid"), params.getString("projectid"));
编辑:或者您可以在通知中发送声音:
mPushManager.setVibrateNotificationType(VibrateType.ALWAYS);
mPushManager.setSoundNotificationType(SoundType.ALWAYS);
请参阅:[1]