当我订阅解析推送通知的频道时,我的Android应用程序冻结

时间:2015-03-02 11:34:41

标签: android parse-platform push-notification

您好我正在关注Android推送通知教程,我的应用程序只是在我运行时冻结然后超时发生。但是在应用程序类中,如果我删除ParsePush.subscribeInBackground,应用程序运行正常。而我的应用程序只有一个打印hello world的活动。感谢帮助。

我的清单是:

    <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.swipeit.swipeit" />
        </intent-filter>
    </receiver>

Application.java

public class Application extends android.app.Application {
public Application() {

}

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

    Parse.enableLocalDatastore(this);

    Parse.initialize(this, "TXLfgM7jiXbdeeQQin5CMy7tQHpZ3mXKhVh2Rb7o", "6tRKnMrAlkYeCCP7JO4p4qmzsr2kDctCafno5f5i");


    ParsePush.subscribeInBackground("", new SaveCallback() {

        @Override
        public void done(com.parse.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);
            }
        }
    });

//     ParseInstallation.getCurrentInstallation().saveInBackground();
}
}

这是我得到的logcat:

1658-1658/com.google.android.gms I/ConfigFetchService﹕ fetch service done; releasing wakelock
03-02 11:35:23.910    1658-1658/com.google.android.gms I/ConfigFetchService﹕ stopping self
03-02 11:35:23.920    1801-1801/com.google.process.gapps I/ConfigService﹕ onDestroy
03-02 11:35:24.060    1312-1330/system_process W/ActivityManager﹕ Launch timeout has expired, giving up wake lock!
03-02 11:35:25.910    1312-1336/system_process W/BatteryStatsImpl﹕ Couldn't get kernel wake lock stats
03-02 11:36:00.020    1312-1330/system_process I/ProcessStatsService﹕ Prepared write state in 0ms
03-02 11:36:00.070    1312-1329/system_process I/ProcessStatsService﹕ Pruning old procstats: /data/system/procstats/state-2015-02-07-22-15-38.bin

1 个答案:

答案 0 :(得分:0)

试试这个

<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="in.appera.generalQuiz.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="in.appera.generalQuiz.permission.C2D_MESSAGE" />

 <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: 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="in.appera.generalQuiz" />
        </intent-filter>
    </receiver>