解析推送通知在安卓设备上无法工作

3
我正在使用 Parse 推送通知来为我的安卓应用提供服务。我按照教程下载了 JAR 文件,并将其导入到我的项目中,然后将以下代码添加到我的清单文件中:
<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>

我将application.class添加到了我的包中,代码如下:

public class Application extends android.app.Application {

    public Application() {
    }

    @Override
    public void onCreate() {
        super.onCreate();

        // Initialize the Parse SDK.
        Parse.initialize(this, "zzxxxxxxxxxxxxxxVv", "wyxxxxxxxCElxxxxxxx"); 

        // Specify a Activity to handle all pushes by default.
        PushService.setDefaultPushCallback(this, MainActivity.class);

        // Save the current installation.
        ParseInstallation.getCurrentInstallation().saveInBackground();
    }
}

在我的主活动中,我这样做
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ParseAnalytics.trackAppOpened(getIntent());

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    Log.e("MainActivity", "oncreate");
    setContentView(R.layout.activity_main);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

有人说这可能是应用程序清单中名称属性的问题,所以我使用我的包名添加了这行代码。
 <application
    android:name="com.test.pushnotificationTest.Application"

在 Parse 仪表盘中,当我在新设备上安装应用程序后,我会在仪表盘中得到新的条目。但是,当我尝试发送推送通知时,我却没有收到通知。 我需要添加广播接收器吗?但是以前使用同样的代码而没有广播也可以工作。 请帮帮我。


你检查了你的应用程序的解析认证代码了吗? - Aashir
@user2558344 你是指应用程序ID和客户端ID对吧?...是的,我已经检查过了。 - user1597878
你能添加一些详细信息描述你是如何发送这些通知以及它们针对哪些安装进行的吗? - Héctor Ramos
1
@HectorRamos 我使用 Parse https://parse.com 发送通知,通过应用程序 ID 和 KEY Parse.initialize() 来识别需要显示通知的应用程序...这就是 Parse 教程所说的,我是对的吗? - user1597878
你是否已经在Parse.com上启用了推送通知设置? - Aashir
@user2558344 是的,我已经做了那个... - user1597878
4个回答

3

解析通知器使用端口号8253。 如果在您的网络中被阻止,通知将无法接收! 因此,请尝试其他互联网连接...这是我解决这个问题的方法!


默认是否被阻止,还是您有一个使用该端口的应用程序? - Mightian

3

解析API有时会在向Android推送消息时出现延迟...当我签署我的APK文件时,我收到了推送通知。请使用已签署的APK文件再次尝试。


如果你在防火墙后面,请确保端口8253是开放的。 - Muayyad Alsadi
@muayyadalsadi 我该如何解除对8253端口的阻止? - Zen

1
应该有两个接收器标签。另一个应该是这样的。
<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: If you change the package name of this sample app,
                  change "com.parse.tutorials.pushnotifications" in the lines
                  below to match the new package name.
                -->
                <category android:name="com.example.ifis" />
            </intent-filter>
        </receiver>

0

将此代码添加到您的委托或活动的onCreate方法中

ParsePush.subscribeInBackground("[channel name]", new SaveCallback() {
          @Override
          public void done(ParseException e) {
            if (e == null) {
              Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
            } else {
              Log.e("com.parse.push", "failed to subscribe for push", e);
            }
          }
        });

这个真的需要添加吗? - portfoliobuilder

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接