0

我是 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 文件,我预计这一切都会出错,哈哈。

<?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 应用程序崩溃

使用 PushBots 进行 Android 推送通知

4

2 回答 2

2

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

我也会在这里引用:

请确保您已将 PushBots.jar 文件复制到您的 android 项目的库文件夹中。并确保您扩展了应用程序类,并在其 onCreate 方法中初始化了 PushBots,查看此链接中的步骤 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, "",""); }
}
于 2013-10-29T10:26:45.630 回答
0

似乎 Pushbots 开发人员为您提供了一种等于配置初始化的新方法。请检查一下pushbotdeveloping的一侧,它将逐步为您提供路线。我已经通过这种方式解决了我的问题。

于 2015-02-17T15:35:27.487 回答