gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 06:37:58 24 4
gpt4 key购买 nike

我是 Java 和 Android 编程的初学者,我已经按照 PushBot 教程创建了一个工作应用程序。但是,如果应用程序未在前台运行,则在收到推送通知时该应用程序会崩溃。因此,我在这里和 Pushbots 网站上进行了一些搜索,发现了有关将类扩展到应用程序的信息。问题是我无法通过应用程序而不是 Activity 来扩展此方法。我现在已经盯着它看了太久了,我看不到树上的木材,这可能是一个非常简单的修复,我在公共(public)类 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 App Crash

Using PushBots for android push notification

最佳答案

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

我也在这里引用:

Please make sure you've copied PushBots.jar file into libraries folder of your android project. And also make sure you extended Application Class, and initialized PushBots in its onCreate method, check out steps 6,7 in this link for more details 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, "",""); }
}

关于java - PushBot 接收推送通知会导致应用程序在未运行时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19452144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com