我是 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>
这些是我一直在看的页面: