使用Parse无法在Android中接收推送通知 [英] Unable to receive push notification in Android using Parse

查看:61
本文介绍了使用Parse无法在Android中接收推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在解析"控制台中,它显示交付"报告已成功,但是onPushReceive根本没有被调用.我在这里想念什么?任何帮助,将不胜感激.

In Parse console it shows Delivery report as successful, but onPushReceive is not getting called at all. What am I missing here? any help would be appreciated.

下面是我的代码. 清单代码:

Below is my code. Manifest code:

    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.appname" />
        </intent-filter>
    </receiver>

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

    <receiver android:name="com.appname.PushReceiver"
        android:permission="com.google.android.c2dm.permission.SEND"
        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" />

            <!--IMPORTANT: Change "com.parse.starter" to match your app's package name.-->

            <category android:name="com.appname" />
        </intent-filter>
    </receiver>

PushReceiver类:

PushReceiver class:

public class PushReceiver extends ParsePushBroadcastReceiver
{

@Override
protected void onPushReceive(Context context, Intent intent) {
    super.onPushReceive(context, intent);

    Log.v("Push Receive called...", "");


    if (intent == null)
        return;

    try
    {
        JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));



    } catch (JSONException e) {
        e.printStackTrace();
    }
}



}

推荐答案

以下是您应该在清单中拥有的权限:

Here're permissions you should have in your manifest:

<!-- Push Permissions -->
    <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="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission android:protectionLevel="signature"
        android:name="your_package_name.permission.C2D_MESSAGE" />
    <uses-permission android:name="your_package_name.permission.C2D_MESSAGE" />

以下是您应该在清单中定义的其他内容:

Here're other stuff you should define in your manifest:

<service android:name="com.parse.PushService" />
        <receiver android:name="com.parse.ParsePushBroadcastReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </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="your_package_name" />
            </intent-filter>
        </receiver>

等级依赖性:

compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'

使用此清单配置,我可以成功接收来自解析的推送.

With this manifest configuration i can successfully receive pushes from parse.

这篇关于使用Parse无法在Android中接收推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆