Parse.com推送通知没有得到后台设备 [英] Parse.com push notifications don't get to devices on background

查看:155
本文介绍了Parse.com推送通知没有得到后台设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我在我的应用程序实现Parse.com推送服务。 我注意到,推送通知发送,只有当应用程序是开放的。我也注意到,每当我把我的设备上有一条消息说不幸的是,飞行时间已停止。在LogCat中说,无法启动接收器。

Today I've implemented Parse.com Push service in my app. I've noticed that the push notifications are being sent only when the app is open. I've also noticed that whenever I'm turning on my device there is a message says "Unfortunately, tof has stopped". The Logcat says Unable to start receiver.

全logcat的:

java.lang.RuntimeException: Unable to start receiver com.parse.ParseBroadcastReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.parse.ParsePlugins$Android.applicationContext()' on a null object reference
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:2952)
        at android.app.ActivityThread.access$1800(ActivityThread.java:172)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:145)
        at android.app.ActivityThread.main(ActivityThread.java:5832)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.parse.ParsePlugins$Android.applicationContext()' on a null object reference
        at com.parse.Parse.checkContext(Parse.java:440)
        at com.parse.Parse.getApplicationContext(Parse.java:270)
        at com.parse.ManifestInfo.getContext(ManifestInfo.java:324)
        at com.parse.ManifestInfo.getPackageManager(ManifestInfo.java:328)
        at com.parse.ManifestInfo.getPackageInfo(ManifestInfo.java:358)
        at com.parse.ManifestInfo.deviceSupportsGcm(ManifestInfo.java:446)
        at com.parse.ManifestInfo.getPushType(ManifestInfo.java:212)
        at com.parse.PushService.startServiceIfRequired(PushService.java:222)
        at com.parse.ParseBroadcastReceiver.onReceive(ParseBroadcastReceiver.java:19)
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:2945)
        at android.app.ActivityThread.access$1800(ActivityThread.java:172)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:145)
        at android.app.ActivityThread.main(ActivityThread.java:5832)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)

我试着在网上搜索上,但我没有找到任何解决方案。我想,这件事情对接收器的后台操作。

I've tried to search on the Web but I didn't find any solution. I guess that it's something about the receiver background operation.

我需要一个答案尽快,所以如果你知道一些关于解析SDK和它的推论题所以,请帮助我,因为我需要解决这个今天

I need an answer as quickly as possible, so if you know a bit about Parse SDK and it's push topic so please, help me 'cause I need to solve this today.

这是我的code。
MainActivity.java:

This is my code.
MainActivity.java:

ParsePush parsePush = new ParsePush();
ParseQuery pQuery = ParseInstallation.getQuery(); // <-- Installation query
pQuery.whereEqualTo("username", User_Name); 
parsePush.sendMessageInBackground(message, pQuery);

AndroidManifest.xml中:

AndroidManifest.xml:

<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.intap.tof.permission.C2D_MESSAGE" />
<uses-permission android:name="com.intap.tof.permission.C2D_MESSAGE" />

...

<service android:name="com.parse.PushService" />
    <receiver android:name="com.intap.tof.Receiver"
        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.intap.tof" />
        </intent-filter>
    </receiver>

我也有这个行Receiver.java:

I also have this line on Receiver.java:

package com.intap.tof;

import android.content.Context;
import android.content.Intent;

import com.parse.ParsePushBroadcastReceiver;

public class Receiver extends ParsePushBroadcastReceiver {

    @Override
    public void onPushOpen(Context context, Intent intent) {
        Intent i = new Intent(context, MainActivity.class);
        i.putExtras(intent.getExtras());
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

我需要大的帮助,现在!请帮帮我!

I need major help right now!! Please help me!

推荐答案

我明白了为什么我没有得到推送通知的背景。

I've understood why I don't get the push notifications on background.

我已经初始化解析SDK两次 - 对 OpenActivity.java ParseApplication.java 。我已经从删除它的 OpenActivity.java 并添加这个code线:

I've initialized parse sdk twice - on the OpenActivity.java and on ParseApplication.java. I've removed it from the OpenActivity.java and added this code line:

android:name=".ParseApplication"

应用程序的Andr​​oidManifest.xml 属性,现在我可以得到推送通知的背景。

To the application attribute on the AndroidManifest.xml and now I can get push notifications on background.

这篇关于Parse.com推送通知没有得到后台设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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