gpt4 book ai didi

android - 无法实例化 GcmBroadcastReceiver

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:30:30 25 4
gpt4 key购买 nike

根据 Google 手册 https://developer.android.com/google/gcm/client.html#app,我尝试使用 GCM 服务创建测试应用程序

但是当我收到消息时 - 我有这个错误:

Unable to instantiate receiver com.example.testpushnotification.GcmBroadcastReceiver: java.lang.ClassNotFoundException: Didn't find class "com.example.testpushnotification.GcmBroadcastReceiver" on path: DexPathList[[zip file "/data/app/com.example.testpushnotification-2.apk"], nativeLibraryDirectories=[/data/app-lib/com.example.testpushnotification-2, /vendor/lib, /system/lib]]

我一直在寻找所有相同的问题,但他们没有解决方案或解决方案没有帮助或已被弃用。

我的 list :

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


<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<permission android:name="com.example.testpushnotification.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.testpushnotification.permission.C2D_MESSAGE"/>


<application

android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>

<activity
android:name="com.example.testpushnotification.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.testpushnotification"/>
</intent-filter>
</receiver>
<service android:name=".GcmIntentService"/>
</application>

以及com.example.testpushnotification包中GcmBroadcastReceiver的源码:

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}

为什么 Dex 路径包含的包与我的不同?

请问如何解决?

已修复已更改 <receiver
android:name=".GcmBroadcastReceiver"
..
</receiver>

<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
..
</receiver>
(区分大小写)

最佳答案

试试这个:

转到 Project/Properties/Java Build Path/Order and Export -- 确保在 Android Dependencies 和支持库前面有一个检查,如果你使用它。标记所有复选框。单击 Apply 并清理项目。

像这样添加:

   <receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />

<category android:name="com.test.android" />
</intent-filter>
</receiver>

它应该是:com.google.android.gcm.GCMBroadcastReceiver 而不是 .GCMBroadcastReceiver

这对我有用。希望对您有所帮助。

关于android - 无法实例化 GcmBroadcastReceiver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20326835/

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