0

我已经集成了 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

我哪里错了?

谢谢,丹尼尔

4

1 回答 1

1

你必须做一些Java来实现这一点。

转到Android项目,找到PushNotifications类,位于/src/com/pushwoosh/plugin/pushnotifications/并寻找这一行:

mPushManager = new PushManager(cordova.getActivity(), 
    params.getString("appid"), params.getString("projectid"));

然后添加以下行:

mPushManager.setVibrateNotificationType(VibrateType.ALWAYS);
mPushManager.setSoundNotificationType(SoundType.ALWAYS);

编辑:或者您可以在通知本身中发送声音:

"android_sound" : "soundfile", // Optional. Sound file name in the "res/raw" folder, do not include the extension

见:[1]

于 2013-01-23T15:00:55.110 回答