【问题标题】:GCM message isn't coming in my app, when my app is closed当我的应用关闭时,GCM 消息没有出现在我的应用中
【发布时间】:2016-11-13 05:17:12
【问题描述】:

我想在我的应用程序关闭或从缓存中清除时向用户显示我的 GCM 通知,下面是我的代码,它仅在应用程序打开但不在后台运行时工作:

public function send_notification($registatoin_ids, $message) {
    include_once 'dbconfig.php';
    // Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';
    $fields = array(
        'registration_ids' => $registatoin_ids,
        'data' => $message,
    );

智能手机在我的应用中看不到任何服务。这是一个屏幕截图,您可以在其中将我的应用程序与其他应用程序(如 whatsapp)进行比较:

以下是我关于 GCM 的清单部分:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.app.path" >    

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<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" />
 <!-- ... other permissions -->

<permission
    android:name="my.app.path.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="my.app.path.permission.C2D_MESSAGE" />

<application
    ...>
     <!-- ... activites... -->

    <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="my.app.path" />
        </intent-filter>
    </receiver>      

    <service
        android:name=".MyGcmListener"
        android:exported="false"
        android:enabled="true" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>

</application>

</manifest>

我想显示类似 WhatsApp 的通知。

【问题讨论】:

标签: php android json google-cloud-messaging android-5.0-lollipop


【解决方案1】:

您是否尝试过在发送消息时将优先级设置为high 是否有帮助?

设置为 High priority 允许 GCM 服务在可能的情况下唤醒睡眠设备并打开与您的应用服务器的网络连接。例如,具有即时消息、聊天或语音呼叫警报的应用程序通常需要打开网络连接并确保 GCM 将消息及时传递到设备。仅当消息时间紧迫且需要用户立即交互时才设置高优先级,并注意将消息设置为高优先级比正常优先级消息更容易消耗电池电量。

【讨论】:

  • 我已经尝试过这个解决方案,在发送消息时设置高优先级选项,但它没有解决我的问题
猜你喜欢
  • 2021-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-05
相关资源
最近更新 更多