无法实例化 GcmBroadcastReceiver

2024-01-02

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

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

无法实例化接收器 com.example.testpushnotification.GcmBroadcastReceiver: java.lang.ClassNotFoundException:未找到类 路径上的“com.example.testpushnotification.GcmBroadcastReceiver”: DexPathList[[zip 文件 “/data/app/com.example.testpushnotification-2.apk”], nativeLibraryDirectories=[/data/app-lib/com.example.testpushnotification-2, /供应商/lib,/系统/lib]]

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

我的清单:

<?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 路径包含与我不同的包?

请问,如何解决?

FIXED改变了<receiver android:name=".GcmBroadcastReceiver" .. </receiver>

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


尝试这个:

转到 Project/Properties/Java Build Path/Order and Export - 确保 Android Dependency 和支持库前面有一个复选框(如果您使用它)。标记所有复选框。单击“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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法实例化 GcmBroadcastReceiver 的相关文章

随机推荐

  • rspec 测试检查 #new 是否在类上调用

    当满足 if 条件 创建 DispatchMessenger 的实例 时 我尝试为以下方法编写测试 class Telephony def self receive body opts responder Responder find by
  • geom_vline 与字符 xintercept

    我有一些 ggplot 代码在 0 8 9 中运行良好 但在 0 9 1 中不行 我将把数据绘制在theDF并想在以下位置绘制一条垂直线xintercept 2010 Q1 theGrid仅用于创建theDF theGrid lt expa
  • 如何在 selenium-docker 项目中的 Headless Chrome >= 96 中启用 WebGL,以便在没有 XVFB 的情况下在 docker 容器内运行 Chrome

    我正在使用 selenium docker 项目在 docker 容器内运行 chrome 无需XVFB START XVFB false 我想使用 webgl 支持 使用 chrome v95 及更低版本 https github com
  • 如何阻止控制台窗口立即关闭 | GNAT-GPS

    我有 Ada 程序 可以使用 GNAT GPS 完美运行和编译 当我运行其 exe 文件并提供用户输入时 该 exe 会立即关闭 而不是说 按任意键继续 我在网上搜索了很多 但我只找到了与使用 system pause 的 c c visu
  • 为什么这个计算(除法)会返回错误的结果?

    我在使用 C 时遇到了一个奇怪的问题 在 OpenGL 代码中 我尝试用这种方式计算一个简单的表达式 void mouse int button int state int x int y double posx x 300 300 dou
  • 如何在 Go 中进行 SOAP 调用? [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 无法在 PHP 中使用 exec() 运行 .exe 文件

    我正在尝试使用 exe 文件来执行计算并将输出传递到 PHP 中 我使用 C 制作了一个 Hello World exe 文件 但无法让 PHP 执行它 如果我从 CMD 运行此命令 我会得到正确的输出 C path file exe 但如
  • 如何在等待 AJAX 响应时加载图像?

    我想知道是否可以得到一些指点 我正在尝试使用加载 gif 同时获取 ajax 请求的响应 我遇到的问题是发送电子邮件时不会显示 gif 我已经查看了这里的几页 试图找到解决方案 但似乎都不起作用 这些是我看过的页面 jQuery ajax
  • 在 javascript 中从文本文件中搜索字符串

    我正在使用 Java 脚本创建一个移动词典应用程序 我已将字典源存储在单独的文件中 我的疑问是如何访问该文件并使用 Java 脚本搜索特定字符串 function dic var word document getElementById w
  • 如何捕获并处理“_com_error”?

    我目前有这样的代码 IAcctMaintPtr acct uuidof AcctMaint acct gt GetAccountList q 现在 此代码需要运行外部应用程序 否则在第一个语句之后我会收到一个异常 说明 myapp exe
  • 在 C# 和 DLL 之间传递数组数据(双向)

    我有一些可以编译为 DLL 的 C 代码 在 C 中 我需要将一个整数数组传递给它 并且需要从中获取一个整数数组 这是我到目前为止所拥有的 在 C 中 唯一有效的函数是 bar 它返回 22 并按预期写入文件 其他人正确写入文件 但在控制权
  • WooCommerce - 获取购物车中产品的选定变体

    Hello 任何人请帮我找到解决方案 我的客户有一家批发业务 他不需要 woocommerce 结账功能 他需要购物车中的 woocommerce 功能 但他想要一个 下订单 按钮 而不是结帐 现在 一切正常 正确下订单 订单存储到数据库中
  • java中如何将数据保存到文件中?

    我有一个问题 那就是我有一串数据 我想每次都将其保存到一个单独的文件中 请给我一个建议 谢谢 瓦拉 库马尔 pjd 在文件名中使用时间戳 这样您就可以确保它是唯一的 下面的示例使用以毫秒为单位的时间戳 这在大多数情况下应该足够了 如果您希望
  • 按顺序连接字段 - SQL Server

    我有一个由 5 个整数 id 组成的表 并且想添加一个列来获取这些 id 对它们进行排序并以类似于下面的方式连接它们 id1 id2 id3 id4 id5 new col 364 53 468 184 469 53 184 364 468
  • 如何为自定义指令实现 ng-change

    我有一个带有模板的指令 例如 div div div 我的指令声明为 return templateUrl restrict E require ngModel scope items ngModel ngChange link funct
  • 如何获取程序中特定字符串占用的字节数?

    我使用 BSPlib 我想使用 bsp put 它要求我设置要发送的字符串的大小 即使您不熟悉 BSP 这也不是密切相关的 谢谢 乘以字符数 由下式给出 size or capacity 如果您想通过字符类型的大小了解分配的总量而不是使用的
  • 在matlab中绘制多个系列

    以下命令会产生一些非常奇怪的结果 plotyy 1 3 2 4 3 5 4 6 hold on plotyy 1 3 2 1 4 1 3 5 4 1 6 1 我基本上想在左侧 y 轴上绘制两个不同的系列 在右侧 y 轴上绘制另外两个系列 上
  • 如何使用记录器打印异常?

    我有一种情况 我想使用记录器打印 catch 块中捕获的所有异常 try File file new File C className mkdir fh new FileHandler C className className log l
  • Apache Flink RollingFileAppender

    我正在使用 Apache Flink v1 2 我想切换到滚动文件附加程序 以避免包含几天数据的巨大日志文件 然而它似乎不起作用 我调整了 log4j 配置 log4j properties 如下 log4j appender file o
  • 无法实例化 GcmBroadcastReceiver

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