PushBot接收推送通知会在应用程序未运行时崩溃

时间:2013-10-18 14:26:37

标签: java android push-notification

我是Java和Android编程的初学者,我已经按照PushBot教程创建了一个有用的应用程序。但是,如果应用程序未在前台运行,则会在收到推送通知时崩溃。所以我在这里和pushbots网站上进行了一些搜索,发现将类扩展到应用程序。问题是我无法通过应用程序而不是活动来扩展此方法。我现在一直盯着它这么久我看不到树上的木头,它可能是一个非常简单的修复我在公共类Myapplication行上得到一个错误并且无法编译(它必须在文件中明确定义) ):

继承人代码:

package co.uk.mypchealth.pushbottest;

import com.pushbots.push.Pushbots;
import android.app.Application;

public class MyApplication extends Application {     

private String SENDER_ID = "Oh know you dont :) My sender id here ";
private String PUSHBOTS_APPLICATION_ID = "oh know you dont :) my app id here";

@Override    
public void onCreate() {
    super.onCreate();        
    Pushbots.init(this, SENDER_ID,PUSHBOTS_APPLICATION_ID);     }  } 

这是Mainifest文件,我希望这一切都非常糟糕lol。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.uk.mypchealth.pushbottest"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
<permission android:name="co.uk.mypchealth.pushbottest.permission.C2D_MESSAGE"    android:protectionLevel="signature" />
<uses-permission android:name="co.uk.mypchealth.pushbottest.permission.C2D_MESSAGE" />     
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:name="co.uk.mypchealth.pushbottest.MyApplication"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"

    >

    <activity
        android:name="co.uk.mypchealth.pushbottest.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter>    
            <action android:name="co.uk.mypchealth.pushbottest.MESSAGE" />    
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

    </activity>

        <activity android:name="com.pushbots.push.PBMsg"/>
        <activity android:name="com.pushbots.push.PBListener"/>
        <receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <!-- Receives the actual messages. -->
                <action     android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category    android:name="co.uk.mypchealth.pushbottest" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.pushbots.push.MsgReceiver" />
        <service android:name="com.pushbots.push.GCMIntentService" />
        <service android:name="org.openudid.OpenUDID_service" >
            <intent-filter>
                <action android:name="org.openudid.GETUDID" />
            </intent-filter>
        </service>
</application>

</manifest>

这些是我一直关注的页面:

https://pushbots.com/developer/tutorial#/android/new/step/5

PushBots App Crash

Using PushBots for android push notification

2 个答案:

答案 0 :(得分:2)

查看youtube上的视频教程(http://www.youtube.com/watch?v=faop6vBBe3E

我也会在这里引用:

  

请确保您已将PushBots.jar文件复制到libraries文件夹中   你的android项目。并确保您扩展了应用程序   在onCreate方法中类和初始化的PushBot,请查看   有关详细信息,请参阅此链接中的步骤6,7   https://pushbots.com/developer/tutorial#/android/existing/step/4

步骤6,7

这是一个示例代码:

import com.pushbots.push.Pushbots;
import android.app.Application;

public class MyApplication extends Application {
@Override public void onCreate() { >super.onCreate();
Pushbots.init(this, "",""); }
}

答案 1 :(得分:0)

似乎Pushbots开发人员为您提供了一种新方法,它等同于配置启动。请检查那一侧pushbotdeveloping它会一步一步地给你路线。我通过这种方式解决了我的问题。