1

我有一个 PHP 代码来发送推送通知,PHP 脚本返回 `{"result":true} 但它没有显示在设备上。我想我需要编写一个自定义接收器代码。我的 Receiver 类为:

package com.phpand;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class ParseReceiver extends BroadcastReceiver {

private static final String TAG = ParseReceiver.class.getName();

@Override
public void onReceive(Context context, Intent intent) {

    Bundle extras = intent.getExtras();
    String message = extras != null ? extras
            .getString("customdata") : "";
    JSONObject jObject;
    try {
        jObject = new JSONObject(message);
        Log.d(TAG,
                jObject.getString("alert")
                        + jObject.getString("action"));
    } catch (JSONException e1) {
        e1.printStackTrace();
    }

}
}

和清单为:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.phpand"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="14" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name=".permission.RECEIVE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="com.phpand.permission.C2D_MESSAGE" />

    <permission
        android:name="com.phpand.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity android:name="com.phpand.ParseMainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>


     </activity>
   <service android:name="com.parse.PushService" />

        <receiver android:name="com.parse.ParseBroadcastReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.phpand.ParseReceiver"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.OPEN" />
                <action android:name="com.parse.push.intent.DELETE" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.parse.GcmBroadcastReceiver"
            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.MyStuff.stuff" />
            </intent-filter>
        </receiver>
        </application>

    </manifest>

谁能帮我摆脱困境。注意:所有 Push 消息都显示在 parse.com 的仪表板上

4

0 回答 0