【问题标题】:Push notification not working using sample code from Parse.com使用 Parse.com 的示例代码推送通知不起作用
【发布时间】:2015-09-16 03:58:29
【问题描述】:

过去两天我一直在使用 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

【问题讨论】:

  • 你为什么不试试this教程。我已经做到了,而且效果很好。
  • 安装对象是否有通道值?然后你要推送到那个频道吗?
  • Kavish:感谢您的教程,但我选择了 parse.com 以避免设置自己的服务器
  • Andrew Breen:我是不是特别需要在安装对象中设置一个通道值?我在后台订阅时指定了一个频道。从 parse.com 仪表板发送推送通知时,我尝试使用渠道和电子邮件,但都无法到达设备。

标签: android push-notification


【解决方案1】:

解析推送通知需要 Google Play 商店和用户在 Android 模拟器中登录 Play 商店才能工作。按照平台和模拟器的具体说明启用 google play store。

【讨论】:

    猜你喜欢
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    相关资源
    最近更新 更多