应用关闭或应用徽章点击时,Android Parse.com推送通知崩溃

时间:2015-03-28 12:54:33

标签: android parse-platform push-notification android-notifications

按照官方指南,在应用程序打开时正确接收推送通知。 当应用程序处于后台时,我会收到通知,但是当点击徽章时会崩溃。 应用程序关闭时相同,但我没有收到任何通知,它会崩溃并给我以下内容:

E/com.parse.PushService﹕ The Parse push service cannot start because Parse.initialize has not yet been called. If you call Parse.initialize
 from an Activity's onCreate, that call should instead be in the Application.onCreate. 
Be sure your Application class is registered in your AndroidManifest.xml with the
 android:name property of your <application> tag.

    java.lang.RuntimeException: Unable to start service com.parse.PushService@4263802d0
 with Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10 pkg=com.xxxxx.xxxxx 
cmp=com.xxx.xxxxxx/com.parse.PushService (has extras) }: java.lang.RuntimeException: applicationContext is null. 
You must call Parse.initialize(Context) before using the Parse library.

试图跟随类似的帖子,但仍然无法正常工作。

public class Application extends android.app.Application {
    public Application() {
    }
    @Override
    public void onCreate() {
        super.onCreate();
// Initialize the Parse SDK.
        Parse.enableLocalDatastore(this);
        Parse.initialize(this, "dzSJWNKJYWgfPykS90u9TlpWrqCljSsOI", "IEGU9e6mBqZsajxDlI5pFIV");
// Specify an Activity to handle all pushes by default.
        PushService.setDefaultPushCallback(this, Welcome.class);
    }
}

    public class Welcome extends Activity {
Context context;
    SessionManagement session;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        Parse.enableLocalDatastore(this);
        Parse.initialize(this, "dzSJWNKJYWgfrykS90u9TlpWrqCljSsOI", "IEGU9e6mBqZsajxDehmvQ149OILfpFIV");
        // Track app opens.
        ParseAnalytics.trackAppOpened(getIntent());
        ParsePush.subscribeInBackground("Global", 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);
                }
            }
        });

这是我的清单:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxxxxxxx.xxxxxx" >
<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <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.RECEIVE_BOOT_COMPLETED" />
    <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.xxxxxxx.xxxxx.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.xxxxxxx.xxxxx.permission.C2D_MESSAGE" />

    <application
        android:name=".app.AppController"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Welcome"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
<!-- PARSE -->
        <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>
        </receiver>
        <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.xxxxx.xxxxxxx" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

对于最终的rendoundant代码感到抱歉,这是许多尝试的结果。 任何人都知道如何解决它? 任何帮助将不胜感激。

0 个答案:

没有答案