使用Parse.com中的示例代码推送通知无效

时间:2015-09-16 03:58:30

标签: android push-notification

过去两天我一直在玩parse.com的推送通知,但无法让它发挥作用。

我从parse.com下载了示例代码并进行了一些小的更改。在我的parse.com仪表板上,我可以看到该应用已注册。当我通过仪表板发送推送通知时,我收到了成功消息,但我没有在Android模拟器上收到通知。

这是清单文件:

<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (c) 2015-present, Parse, LLC.
  ~ All rights reserved.
  ~
  ~ This source code is licensed under the BSD-style license found in the
  ~ LICENSE file in the root directory of this source tree. An additional grant
  ~ of patent rights can be found in the PATENTS file in the same directory.
  -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.parse.starter" >

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

    <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" />

    <!--
      IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
      to match your app's package name + ".permission.C2D_MESSAGE".
    -->
    <permission android:protectionLevel="signature"
                android:name="com.parse.starter.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />

    <application
        android:name=".StarterApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <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.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" />

                <!--
                  IMPORTANT: Change "com.parse.starter" to match your app's package name.
                -->
                <category android:name="com.parse.starter" />
            </intent-filter>
        </receiver>

    </application>

</manifest>

这是应用程序类

public class StarterApplication extends Application
{
  @Override
  public void onCreate()
  {
    super.onCreate();

    Parse.initialize(this, "xxxx", "yyy");

    ParseInstallation installation = ParseInstallation.getCurrentInstallation();
    installation.put("email", "jpc@acme.com");
    installation.saveInBackground();

    ParsePush.subscribeInBackground("Emulator1", new SaveCallback()
    {
      @Override
      public void done(ParseException e)
      {
        if (e != null)
          Log.d("#### DEBUG", "Parse subscription failed with error: " + e.toString());
        else
          Log.d("#### DEBUG", "Subscribed to parse");
      }
    });
  }
}

有人可以帮忙吗? TIA

1 个答案:

答案 0 :(得分:0)

解析推送通知需要 Google Play商店&amp;用户要在Android模拟器内登录Play商店才能工作。按照平台和模拟器特定说明启用Google Play商店。