0

我创建了一个 Ionic/AngularJS 应用程序,并且正在使用 PushPlugin 进行推送通知。当我在应用程序内并收到通知时,我会收到通知并且一切正常。

但是当我离开应用程序并在通知栏中收到通知并点击它时,我会在日志文件中看到:

  07-01 10:56:51.651: W/ActivityManager(3037): java.lang.SecurityException: 
  Permission Denial: starting Intent { flg=0x24000000 cmp=za.co.vine.gcom.phonegap.test/com.plugin.gcm.PushHandlerActivity bnds=[0,1021][1080,1213] (has extras) } from null (pid=-1, uid=10261) not exported from uid 10275
  07-01 10:56:51.651: W/ActivityManager(3037):  at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1669)
  07-01 10:56:51.651: W/ActivityManager(3037):  at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:977)
  07-01 10:56:51.651: W/ActivityManager(3037):  at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:4182)
  07-01 10:56:51.651: W/ActivityManager(3037):  at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:252)
  07-01 10:56:51.651: W/ActivityManager(3037):  at com.android.server.am.PendingIntentRecord.send(PendingIntentRecord.java:192)
  07-01 10:56:51.651: W/ActivityManager(3037):  at android.content.IIntentSender$Stub.onTransact(IIntentSender.java:64)
  07-01 10:56:51.651: W/ActivityManager(3037):  at android.os.Binder.execTransact(Binder.java:404)
  07-01 10:56:51.651: W/ActivityManager(3037):  at dalvik.system.NativeStart.run(Native Method)

我使用 phonegap build 来构建应用程序 - 它的版本 3.4.0

我看到有些人建议在 AndroidManifest 字段中添加exported=true,但我不能使用Phonegap 构建。

来自 LogCat 的更多日志行:

  07-02 11:11:41.846: V/GCMBroadcastReceiver(29009): onReceive: com.google.android.c2dm.intent.RECEIVE
  07-02 11:11:41.851: V/GCMRegistrar(29009): Setting the name of retry receiver class to com.plugin.gcm.CordovaGCMBroadcastReceiver
  07-02 11:11:41.851: V/GCMBroadcastReceiver(29009): GCM IntentService class: com.plugin.gcm.GCMIntentService
  07-02 11:11:41.851: V/GCMBaseIntentService(29009): Acquiring wakelock
  07-02 11:11:41.871: V/GCMBaseIntentService(29009): Intent service name: GCMIntentService-GCMIntentService-1
  07-02 11:11:41.876: D/GCMIntentService(29009): onMessage - context: android.app.Application@42a90348
  07-02 11:11:41.896: W/ApplicationPackageManager(29009): getCSCPackageItemText()
  07-02 11:11:41.931: V/GCMBaseIntentService(29009): Releasing wakelock

这是我的 onNotificationGCM 代码:

  onNotificationGCM = function(e) {
    console.log("gvi.Notifications:onNotificationGCM");

    switch( e.event ) {
        case 'registered':
            if ( e.regid.length > 0 ) {
                // Your GCM push server needs to know the regID before it can push to this device
                // here is where you might want to send it the regID for later use.
                if (self.debug) console.log( 'registration id = '+e.regid );
                pushRegisterSuccessCB( e.regid );
            }
        break;

        case 'message':
            // this is the actual push notification. its format depends on the data model
            // of the intermediary push server which must also be reflected in GCMIntentService.java
            console.log(e);
            if (self.debug) {
                console.log( 'message' );
                console.log( e );

            }
            _retrieveMessages();

            //alert('message = '+e.message+' msgcnt = '+e.msgcnt+' msgid = '+e.msgid+' type = '+e.type);
            if ( e.foreground ) {
                console.log( 'foreground' );

                //var my_media = new Media("/android_asset/www/"+e.soundname);
                //my_media.play();
            }
            else   // otherwise we were launched because the user touched a notification in the notification tray.
            if (e.coldstart) {
                console.log( 'coldstart' );

            }
            else {
                console.log( 'background' );

            }
        break;

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

        default:
          alert( 'An unknown GCM event has occurred' );
          break;
    }
};

和 _retrieveMessages 函数:

  _retrieveMessages = function() {
    if (self.debug) console.log( "gvi.Notifications:_retrieveMessages" );

    if ( window.device !== undefined ) {
        //self._platform = device.platform === undefined? self._platform: device.platform;
        self._uuid = device.uuid === undefined? self._uuid: device.uuid;
        self._model = device.model === undefined? self._model: device.model;
        self._version = device.version === undefined? self._version: device.version;
    }

    _ajaxGet("/cloudMessaging/Register?" +
              "action=retrieve" +
              "&appid=" + self._appKey +
              "&secretkey=" + self._appSecret +
              "&deviceid=" + self._uuid +
              "&recdate=" + new Date().getTime(),
              _retrieveMessageSuccessCB, 
              function (statusCode, json) {if (self.debug) console.log("_sendReceipt:ERR:" + statusCode +" :"+ JSON.stringify(json, null, 2) )});
};

我还看到,当人们降级到 phonegap 2.9 时它可以工作,但我不想那样做。我怎样才能解决这个问题?

4

0 回答 0