【发布时间】: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 的通知。
【问题讨论】:
-
1) 迁移到 FCM 2) 读取 stackoverflow.com/questions/37876257/…
-
如果没有 FCM 是否不可能?我对FCM一无所知
-
检查所有类型的用户权限和使用此链接的权限stackoverflow.com/questions/38422551/…
标签: php android json google-cloud-messaging android-5.0-lollipop