gpt4 book ai didi

java - 无法实例化接收器 GCMBroadcastReceiver

转载 作者:太空宇宙 更新时间:2023-11-03 13:26:08 25 4
gpt4 key购买 nike

我正在关注 http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/ 的指南用于 GCM。

目前我卡在接收通知部分。有时当我运行我的代码时,它会因以下错误而崩溃:

7.517: E/AndroidRuntime(8601): FATAL EXCEPTION: main 7.517: E/AndroidRuntime(8601): java.lang.RuntimeException: Unable to instantiate receiver com.google.android.gcm.GCMBroadcastReceiver: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gcm.GCMBroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.example.someactivity-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.someactivity-1, /vendor/lib, /system/lib]] 7.517: E/AndroidRuntime(8601): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2544) 7.517: E/AndroidRuntime(8601): at android.app.ActivityThread.access$1500(ActivityThread.java:153) 7.517: E/AndroidRuntime(8601): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1345) 7.517: E/AndroidRuntime(8601): at android.os.Handler.dispatchMessage(Handler.java:99) 7.517: E/AndroidRuntime(8601): at android.os.Looper.loop(Looper.java:137) 7.517: E/AndroidRuntime(8601): at android.app.ActivityThread.main(ActivityThread.java:5295) 7.517: E/AndroidRuntime(8601): at java.lang.reflect.Method.invokeNative(Native Method) 7.517: E/AndroidRuntime(8601): at java.lang.reflect.Method.invoke(Method.java:525) 7.517: E/AndroidRuntime(8601): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) 7.517: E/AndroidRuntime(8601): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555) 7.517: E/AndroidRuntime(8601): at dalvik.system.NativeStart.main(Native Method) 7.517: E/AndroidRuntime(8601): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gcm.GCMBroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.example.someactivity-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.someactivity-1, /vendor/lib, /system/lib]] 7.517: E/AndroidRuntime(8601): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53) 7.517: E/AndroidRuntime(8601): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 7.517: E/AndroidRuntime(8601): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 7.517: E/AndroidRuntime(8601): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2539)

这是我的 list :

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

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

<!-- GCM connects to Internet Services. -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!-- Creates a custom permission so only this app can receive its messages. -->
<permission
android:name="com.example.someactivity.permission.C2D_MESSAGE"
android:protectionLevel="signature" />

<uses-permission android:name="com.example.someactivity.permission.C2D_MESSAGE" />

<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<!-- Network State Permissions to detect Internet status -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Permission to vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light" >
<activity
android:name="com.example.someactivity.Login"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.someactivity.fragmentContainer" >
</activity>

<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="com.example.someactivity" />
</intent-filter>
</receiver>

<service android:name=".GcmIntentService" />

</application>

</manifest>

还有我使用的接收器:

private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String newMessage = intent.getExtras().getString("Some Message");
// Waking up mobile if it is sleeping
WakeLocker.acquire(getApplicationContext());

/**
* Take appropriate action on this message
* depending upon your app requirement
* For now i am just displaying it on the screen
* */

// Showing received message
Toast.makeText(getApplicationContext(), "New Message: " + newMessage, Toast.LENGTH_LONG).show();

// Releasing wake lock
WakeLocker.release();
}
};

为什么我没有实例化接收器,我已经更改了包名称。

最佳答案

将 gcm.jar 添加到您的 libs 文件夹。

关于java - 无法实例化接收器 GCMBroadcastReceiver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19557439/

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