Android Parse.com推送通知应用程序在启动时崩溃

时间:2015-05-23 08:58:37

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

我按照parse.com上的教程推送通知。但是我的应用程序在启动时崩溃了。我认为错误发生在清单文件中。

这是我的代码:

的Manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.adla.insurancemobileapplication" >

    <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.RECEIVE_BOOT_COMPLETED" />
    <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.tutorials.pushnotifications.permission.C2D_MESSAGE" in the lines below
      to match your app's package name + ".permission.C2D_MESSAGE".
    -->
    <permission  android:name="com.example.adla.insurancemobileapplication.permission.C2D_MESSAGE" android:protectionLevel="signature"
        />
    <uses-permission android:name="com.example.adla.insurancemobileapplication.permission.C2D_MESSAGE" />

    <application
        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>
        <activity
            android:name=".AddCustomer"
            android:label="@string/title_activity_add_customer" >
        </activity>
        <activity
            android:name=".AddCustomerDetails"
            android:label="@string/title_activity_add_customer_details" >
        </activity>
        <activity
            android:name=".notificationactivity"
            android:label="@string/title_activity_notificationactivity" >
        </activity>
        <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.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.tutorials.pushnotifications" to match your app's package name.
                -->
                <category android:name="com.example.adla.insurancemobileapplication" />
            </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>
        <!-- replace @drawable/push_icon with your push icon identifier -->
        <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/push_icon"/>
    </application>

</manifest>

这是主要活动的onCreate方法:

  protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        n = (EditText) findViewById(R.id.inputName);
        p = (EditText) findViewById(R.id.inputPass);
        // Enable Local Datastore.

        Parse.enableLocalDatastore(this);

        Parse.initialize(this, "QKpM7ar7aWwrbEeTcrSGJ5bDnLMCUtc1kCr26Enl", "MCBdIQ6Y0dTsIoahzJ44UfR1zHZPJMQPwiETwj47");


    }
你能帮我吗?我不知道问题出在哪里。

1 个答案:

答案 0 :(得分:0)

我尝试调用MyApplication类并将其扩展到解决我问题的应用程序。

public class MyApplication extends Application {
    public void onCreate() {
        Parse.initialize(this, "id", "key");
        ParseInstallation.getCurrentInstallation().saveInBackground();
    }
}  

请不要忘记在android manifest

中声明MyApplication课程

<application android:name=".MyApplication" />