相关疑难解决方法(0)

即使App已关闭,也会收到Android推送通知

我尝试过使用Google GCM但是当应用关闭时(从任务管理器中滑动或清除),它不会收到任何推送通知.当我再次打开应用程序时,通知已经消失并丢失.

GCM正致力于: - 应用程序已打开 - 应用程序已最小化

不工作: - 应用程序已关闭(从任务管理器轻扫) - 通过清除任务管理器中所有打开的应用程序关闭应用程序

即使应用程序像Facebook或Instagram一样关闭,我也希望收到推送通知.我怎么能实现这个?这可能在GCM中有用吗?如果有,怎么样?如果没有,那么实现这个的另一种方法是什么?

这是我的代码:

AndroidManifest.xml中

<!-- [START gcm_receiver] -->
    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.example.airwyntin.notificationtest" />
        </intent-filter>
    </receiver>
    <!-- [END gcm_receiver] -->

    <!-- [START gcm_listener] -->
    <service
        android:name=".MyGcmListenerService"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>
    <!-- [END gcm_listener] -->
    <!-- [START instanceId_listener] -->
    <service
        android:name=".MyInstanceIDListenerService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID"/>
        </intent-filter>
    </service>
    <!-- [END instanceId_listener] -->
    <service
        android:name=".RegistrationIntentService"
        android:exported="false">
    </service>
Run Code Online (Sandbox Code Playgroud)

MyGcmListenerService.java:

public class MyGcmListenerService extends …
Run Code Online (Sandbox Code Playgroud)

notifications android push google-cloud-messaging

7
推荐指数
1
解决办法
5914
查看次数

Ionic/Cordova应用程序不会在后台接收推送通知

我的Android应用程序在后台没有收到推送通知,它应该根据文档.

Android设备上的Android应用程序无需运行即可接收消息.只要应用程序设置了正确的广播接收器和权限,系统就会在消息到达时通过Intent广播唤醒Android应用程序.

尝试不同的通知发现它确实在关闭时收到推送通知,当且仅当通知包含属性"message"时,如果没有,它只是丢弃它.(推送通知只是JSON对象).

我的通知包含所有类型的属性,包括"alert","id"和"title",但只有"message"才能让Android唤醒应用.

示例通知不起作用:

{ event: 'message',
  from: '947957531940',
  collapse_key: 'do_not_collapse',
  foreground: true,
  payload: 
   { alert: 'Mensaje de Prueba',
     title: 'Titulo Mensaje de Prueba' } }
Run Code Online (Sandbox Code Playgroud)

例如通知工作:

{ event: 'message',
  from: '947957531940',
  message: 'Contenido del mensaje de prueba.',
  collapse_key: 'do_not_collapse',
  foreground: true,
  payload: 
   { alert: 'Mensaje de Prueba',
     title: 'Titulo Mensaje de Prueba',
     message: 'Contenido del mensaje de prueba.' } }
Run Code Online (Sandbox Code Playgroud)

这是Android标准设计还是我在我的应用程序中做错了什么?

我的应用程序是使用Ionic与Cordova开发的.

PD:请原谅我的英语.

编辑:

这是app.js中.run模块内的Android推送代码,因为ng-cordova指令指定:

if (ionic.Platform.isAndroid()){

  var …
Run Code Online (Sandbox Code Playgroud)

android push-notification phonegap-plugins cordova ionic-framework

4
推荐指数
1
解决办法
5460
查看次数