接收parse.com推送通知后,阿帕奇科尔多瓦应用程序崩溃 [英] apache cordova app crashes after receiving parse.com push notification

查看:151
本文介绍了接收parse.com推送通知后,阿帕奇科尔多瓦应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想parse.com推送通知服务添加到我的科尔多瓦应用程序。我读过parse.com快速入门指南,我已经放在SDK文件中的libs文件夹。之后,我已经添加了C $ CS的$主的java文件和AndroidManifest.xml中。该应用程序正常工作。 parse.com可以接收我的设备令牌,我可以发送推送通知到设备,但后两个或三个推送通知的应用程序将崩溃。

在该目录下载错误信息是这样的:

 二月五日至七日:08:25.185:E / com.parse.PushService(28735):解析推送服务无法启动​​,因为Parse.initialize尚未调用。如果从活动的onCreate调用Parse.initialize,该呼叫而是应该在Application.onCreate。要确保您的应用程序类被注册在AndroidManifest.xml中与安卓的name属性的<应用>标签。
2月5日至七号:08:25.185:D / AndroidRuntime(28735):关闭虚拟机
2月5日至七号:08:25.185:W / dalvikvm(28735):主题ID = 1:螺纹退出与未捕获的异常(组= 0x41b0de48)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):致命异常:主要
2月5日至七号:08:25.185:E / AndroidRuntime(28735):工艺:ir.wedesign.pushapp,PID:28735
2月5日至七号:08:25.185:E / AndroidRuntime(28735):java.lang.RuntimeException的:无法启动服务com.parse.PushService@42b596a8意图{行动= com.google.android.c2dm.intent.RECEIVE FLG = 0x10的PKG = ir.wedesign.pushapp CMP = ir.wedesign.pushapp / com.parse.PushService(有演员)}:java.lang.RuntimeException的:ApplicationContext就是空。使用解析库前必须先调用Parse.initialize(背景下,的applicationID,clientKey)。
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2726)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在android.app.ActivityThread.access $ 2100(ActivityThread.java:139)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1297)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在android.os.Handler.dispatchMessage(Handler.java:102)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在android.os.Looper.loop(Looper.java:136)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在android.app.ActivityThread.main(ActivityThread.java:5105)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在java.lang.reflect.Method.invokeNative(本机方法)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在java.lang.reflect.Method.invoke(Method.java:515)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:792)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在dalvik.system.NativeStart.main(本机方法)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):由:java.lang.RuntimeException的:ApplicationContext就是空。使用解析库前必须先调用Parse.initialize(背景下,的applicationID,clientKey)。
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在com.parse.Parse.checkContext(Parse.java:557)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在com.parse.Parse.getApplicationContext(Parse.java:165)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在com.parse.ManifestInfo.getContext(ManifestInfo.java:221)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在com.parse.ManifestInfo.getPackageManager(ManifestInfo.java:229)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在com.parse.ManifestInfo.getPackageInfo(ManifestInfo.java:240)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在com.parse.ManifestInfo.deviceSupportsGcm(ManifestInfo.java:325)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在com.parse.ManifestInfo.getPushType(ManifestInfo.java:109)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在com.parse.PushService.onStartCommand(PushService.java:377)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):在android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2709)
2月5日至七号:08:25.185:E / AndroidRuntime(28735):10 ...更多
 

这是我的主要的Java文件:

  / *
       授权给下一个Apache软件基金会(ASF)
       以上contributor许可证协议。请参阅通知文件
       分布式与此工作的其他信息
       关于版权的所有权。该asf文件许可证
       你Apache许可证下,2.0版(中
       许可);你可能不使用这个文件除了在合规
       该许可。您可以在获得许可证的副本

         http://www.apache.org/licenses/LICENSE-2.0

       除非适用法律要求或书面同意,
       软件许可证下发布分布在一个
       按原样的基础,没有担保或任何条件
       善良,无论是EX preSS或暗示的保证。查看许可证的
       特定语言的管理许可和限制
       在许可。
 * /

包ir.wedesign.pushapp;

进口android.os.Bundle;
进口org.apache.cordova *。
进口com.parse.Parse;
进口com.parse.ParseAnalytics;
进口com.parse.ParseInstallation;
进口com.parse.PushService;

公共类PushApp扩展CordovaActivity
{
    @覆盖
    公共无效的onCreate(包savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
        //设置以<内容SRC =的index.html/> config.xml中
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html);
        Parse.initialize(这一点,xJK9ZA0Dtsjd8RwoNUUsIHPXzMRbmcxXGWqiw,19g9eUKjLjlUdogHEXStUABNcvy2rA6azb5mXy);
        PushService.setDefaultPushCallback(这一点,PushApp.class);
        。ParseInstallation.getCurrentInstallation()saveInBackground();

    }
}
 

和我的manifest.xml文件是:

 < XML版本=1.0编码=UTF-8&GT?;
<舱单安卓hardwareAccelerated =真的Andr​​oid版本:版本code =1机器人:VERSIONNAME =0.0.1机器人:windowSoftInputMode =adjustPan包=ir.wedesign.pushapp的xmlns:机器人= http://schemas.android.com/apk/res/android">
    <支持屏安卓anyDensity =真正的机器人:largeScreens =真正的机器人:normalScreens =真正的机器人:调整大小=真正的机器人:smallScreens =真正的机器人:xlargeScreens =真/>
    <使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
    <使用-权限的Andr​​oid:名称=android.permission.ACCESS_NETWORK_STATE/>
    <使用-权限的Andr​​oid:名称=android.permission.WAKE_LOCK/>
    <使用-权限的Andr​​oid:名称=android.permission.VIBRATE/>
    <使用-权限的Andr​​oid:名称=android.permission.RECEIVE_BOOT_COMPLETED/>
    <使用-权限的Andr​​oid:名称=android.permission.GET_ACCOUNTS/>
    <使用-权限的Andr​​oid:名称=com.google.android.c2dm.permission.RECEIVE/>
    <许可安卓的ProtectionLevel =签名
        机器人:名称=ir.wedesign.pushapp.permission.C2D_MESSAGE/>
    <使用-权限的Andr​​oid:名称=ir.wedesign.pushapp.permission.C2D_MESSAGE/>

    <应用的Andr​​oid版本:hardwareAccelerated =真正的机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME>
        <活动机器人:configChanges =定位| keyboardHidden |键盘|屏幕尺寸|语言环境机器人:标签=@字符串/ APP_NAME机器人:NAME =PushApp安卓主题=@安卓风格/ Theme.Black.NoTitleBar >
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>
                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
        <服务机器人:名称=com.parse.PushService/>
<接收器的Andr​​oid版本:NAME =com.parse.ParseBroadcastReceiver>
  <意向滤光器>
    <作用机器人:名称=android.intent.action.BOOT_COMPLETED/>
    <作用机器人:名称=android.intent.action.USER_ preSENT/>
  &所述; /意图滤光器>
< /接收器>
<接收器的Andr​​oid版本:NAME =com.parse.GcmBroadcastReceiver
    机器人:权限=com.google.android.c2dm.permission.SEND>
  <意向滤光器>
    <作用机器人:名称=com.google.android.c2dm.intent.RECEIVE/>
    <作用机器人:名称=com.google.android.c2dm.intent.REGISTRATION/>
    <类机器人:名称=ir.wedesign.pushapp/>
  &所述; /意图滤光器>
< /接收器>
    < /用途>
    <使用-SDK安卓的minSdkVersion =10机器人:targetSdkVersion =19/>
< /舱单>
 

我已经搜查,似乎很多开发商有完全相同的问题。我发现在parse.com帮助论坛两个主题: <一href="https://www.parse.com/questions/app-crashes-after-after-screen-unlock">https://www.parse.com/questions/app-crashes-after-after-screen-unlock <一href="https://www.parse.com/questions/cannot-send-push-to-android-after-app-is-closed-until-screen-unlock">https://www.parse.com/questions/cannot-send-push-to-android-after-app-is-closed-until-screen-unlock 而这一次在这里: <一href="http://stackoverflow.com/questions/18962138/android-app-crashes-when-push-is-received-and-app-is-closed">Android应用程序崩溃时,会收到推送和应用程序被关闭

但解决方案不明确的人不知道的Java。我怎样才能改变我的Andr​​oidManifest.xml中和主要的Java文件,使其工作。

在此先感谢

解决方案
  

解析推送服务无法启动​​,因为Parse.initialize尚未调用。   如果从活动的onCreate调用Parse.initialize,该呼叫而是应该在Application.onCreate。   要确保您的应用程序类被注册在AndroidManifest.xml中的Andr​​oid。你标记的name属性。

尝试单独活动与应用,创建一个新的类文件,如: MainApplication。

PushApp.java:

 公共类PushApp扩展CordovaActivity {
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        super.init();
        //设置以&lt;内容SRC =的index.html/&GT; config.xml中
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html);
    }
}
 

MainApplication.java:

 公共类MainApplication扩展应用{
    @覆盖
    公共无效的onCreate(){
        super.onCreate();
        Parse.initialize(这一点,xJK9ZA0Dtsjd8RwoNUUsIHPXzMRbmcxXGWqiw,19g9eUKjLjlUdogHEXStUABNcvy2rA6azb5mXy);
        PushService.setDefaultPushCallback(这一点,PushApp.class);
        。ParseInstallation.getCurrentInstallation()saveInBackground();
    }
}
 

和变化:

 &LT;活动机器人:configChanges =定位| keyboardHidden |键盘|屏幕尺寸|语言环境机器人:标签=@字符串/ APP_NAME机器人:NAME =PushApp安卓主题=@安卓风格/ Theme.Black.NoTitleBar&GT;
 

 &LT;活动机器人:configChanges =定位| keyboardHidden |键盘|屏幕尺寸|语言环境机器人:标签=@字符串/ APP_NAME机器人:NAME =MainApplication安卓主题=@安卓风格/ Theme.Black.NoTitleBar&GT;
 

现在你也应该收到推送通知,当应用程序被关闭/屏幕锁

I want to add parse.com push notification service to my Cordova app. I've read parse.com quick start guide and I've placed SDK file in the libs folder. after that I've added the codes to main java file and AndroidManifest.xml. the app working correctly. parse.com can receive my device token and I can send push notification to the device but after two or three push notification the app will crash.

the error message in the catlog is this:

05-07 02:08:25.185: E/com.parse.PushService(28735): 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.
05-07 02:08:25.185: D/AndroidRuntime(28735): Shutting down VM
05-07 02:08:25.185: W/dalvikvm(28735): threadid=1: thread exiting with uncaught exception (group=0x41b0de48)
05-07 02:08:25.185: E/AndroidRuntime(28735): FATAL EXCEPTION: main
05-07 02:08:25.185: E/AndroidRuntime(28735): Process: ir.wedesign.pushapp, PID: 28735
05-07 02:08:25.185: E/AndroidRuntime(28735): java.lang.RuntimeException: Unable to start service com.parse.PushService@42b596a8 with Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10 pkg=ir.wedesign.pushapp cmp=ir.wedesign.pushapp/com.parse.PushService (has extras) }: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
05-07 02:08:25.185: E/AndroidRuntime(28735):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2726)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at android.app.ActivityThread.access$2100(ActivityThread.java:139)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1297)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at android.os.Handler.dispatchMessage(Handler.java:102)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at android.os.Looper.loop(Looper.java:136)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at android.app.ActivityThread.main(ActivityThread.java:5105)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at java.lang.reflect.Method.invokeNative(Native Method)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at java.lang.reflect.Method.invoke(Method.java:515)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at dalvik.system.NativeStart.main(Native Method)
05-07 02:08:25.185: E/AndroidRuntime(28735): Caused by: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
05-07 02:08:25.185: E/AndroidRuntime(28735):    at com.parse.Parse.checkContext(Parse.java:557)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at com.parse.Parse.getApplicationContext(Parse.java:165)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at com.parse.ManifestInfo.getContext(ManifestInfo.java:221)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at com.parse.ManifestInfo.getPackageManager(ManifestInfo.java:229)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at com.parse.ManifestInfo.getPackageInfo(ManifestInfo.java:240)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at com.parse.ManifestInfo.deviceSupportsGcm(ManifestInfo.java:325)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at com.parse.ManifestInfo.getPushType(ManifestInfo.java:109)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at com.parse.PushService.onStartCommand(PushService.java:377)
05-07 02:08:25.185: E/AndroidRuntime(28735):    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2709)
05-07 02:08:25.185: E/AndroidRuntime(28735):    ... 10 more

this is my main java file:

/*
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
 */

package ir.wedesign.pushapp;

import android.os.Bundle;
import org.apache.cordova.*;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.PushService;

public class PushApp extends CordovaActivity 
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html");
        Parse.initialize(this, "xJK9ZA0Dtsjd8RwoNUUsIHPXzMRbmcxXGWqiw", "19g9eUKjLjlUdogHEXStUABNcvy2rA6azb5mXy");
        PushService.setDefaultPushCallback(this, PushApp.class);
        ParseInstallation.getCurrentInstallation().saveInBackground();

    }
}

and my manifest.xml file is:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="adjustPan" package="ir.wedesign.pushapp" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <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" />
    <permission android:protectionLevel="signature"
        android:name="ir.wedesign.pushapp.permission.C2D_MESSAGE" />
    <uses-permission android:name="ir.wedesign.pushapp.permission.C2D_MESSAGE" />

    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">   
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="PushApp" android:theme="@android:style/Theme.Black.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </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" />
    <category android:name="ir.wedesign.pushapp" />
  </intent-filter>
</receiver>
    </application>
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
</manifest>

I've searched and it seems that many developers have exactly the same problem. I've found two topics in parse.com help forum: https://www.parse.com/questions/app-crashes-after-after-screen-unlock https://www.parse.com/questions/cannot-send-push-to-android-after-app-is-closed-until-screen-unlock and this one here: Android App crashes when push is received and app is closed

but the solutions isn't clear for someone that don't know java. How can I change my AndroidManifest.xml and main java file to make it work.

thanks in advance

解决方案

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 tag.

Try to seperate Activity and Application, create a new class file e.g. MainApplication.

PushApp.java:

public class PushApp extends CordovaActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.init();
        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html");
    }
}

MainApplication.java:

public class MainApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Parse.initialize(this, "xJK9ZA0Dtsjd8RwoNUUsIHPXzMRbmcxXGWqiw", "19g9eUKjLjlUdogHEXStUABNcvy2rA6azb5mXy");
        PushService.setDefaultPushCallback(this, PushApp.class);
        ParseInstallation.getCurrentInstallation().saveInBackground();
    }
}

and change:

<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="PushApp" android:theme="@android:style/Theme.Black.NoTitleBar">

to:

<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="MainApplication" android:theme="@android:style/Theme.Black.NoTitleBar">

now you should also receive push notifications when app is closed / screen is locked

这篇关于接收parse.com推送通知后,阿帕奇科尔多瓦应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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