3

我在HTML5 Phonegap android GCM push notification應用程序中工作。 但是我試了好幾次,但沒有得到:-(GCM推送通知不適用於Android Phonegap應用程序

任何結果,請幫助我..我試圖這從最近三天的工作

現在用推插件:com.phonegap.plugins.PushPlugin

**我JS代碼:

document.addEventListener("deviceready", onDeviceReady, false); 

function onDeviceReady() 
{ 
    alert('deviceready'); 


// result contains any message sent from the plugin call 
    var app = { 
    successHandler: function(result) { 
     alert('Callback Success! Result = '+result) 
    }, 
    errorHandler:function(error) { 
     alert(error); 
    }, 
    onNotificationGCM: function(e) { 
     alert('onNotificationGCM'); 
      switch(e.event) 
      { 
       case 'registered': 
        if (e.regid.length > 0) 
        { 
         console.log("Regid " + e.regid); 
         alert('registration id = '+e.regid); 
        } 
       break; 

       case 'message': 
        // this is the actual push notification. its format depends on the data model from the push server 
        alert('message = '+e.message+' msgcnt = '+e.msgcnt); 
       break; 

       case 'error': 
        alert('GCM error = '+e.msg); 
       break; 

       default: 
        alert('An unknown GCM event has occurred'); 
        break; 
      } 
     } 
    } 
    setTimeout(function(){ 
     var pushNotification = window.plugins.pushNotification; 
     pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"236728063055","ecb":"app.onNotificationGCM"}); 
    },2000); 

} 

**清單文件

<?xml version='1.0' encoding='utf-8'?> 
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.test.pushDummy" xmlns:android="http://schemas.android.com/apk/res/android"> 
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="CordovaApp" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize"> 
      <intent-filter android:label="@string/launcher_name"> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:exported="true" android:name="com.plugin.gcm.PushHandlerActivity" /> 
     <receiver android:name="com.plugin.gcm.CordovaGCMBroadcastReceiver" 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="com.test.pushDummy" /> 
      </intent-filter> 
     </receiver> 
     <service android:name="com.plugin.gcm.GCMIntentService" /> 
    </application> 
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" /> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="android.permission.VIBRATE" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
    <permission android:name="com.test.pushDummy.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
    <uses-permission android:name="com.test.pushDummy.permission.C2D_MESSAGE" /> 
</manifest> 

回答

2

嘗試在設備準備好之外移動該功能。它會工作。

相關問題