代码在向 GCM 注册时获取唤醒锁时卡住

2023-12-08

我正在使用 GCM 为我的项目推送通知,但一直无法获取唤醒锁。

日志消息:

09-03 17:04:05.003: V/GCMBroadcastReceiver(5772): onReceive:com.google.android.c2dm.intent.REGISTRATION
09-03 17:04:05.003: V/GCMBroadcastReceiver(5772): GCM IntentService class: example.pro.GCMIntentService
09-03 17:04:05.049: V/GCMBaseIntentService(5772): Acquiring wakelock

下面是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="example.pro"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- 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="example.pro.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="example.pro.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:name="com.thinkappz.advancedtictactoe.FriendPickerApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <activity
            android:name="com.thinkappz.advancedtictactoe.Splash"
            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.google.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
        <activity
            android:name="com.thinkappz.advancedtictactoe.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name=".MainActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.thinkappz.advancedtictactoe.GcmMainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name=".GcmMainActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.thinkappz.advancedtictactoe.NewGame"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="example.pro.NewGame" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.thinkappz.advancedtictactoe.Vs_Facebook"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="example.pro.Vs_Facebook" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.thinkappz.advancedtictactoe.RandomPlayer"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="example.pro.RandomPlayer" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.thinkappz.advancedtictactoe.Register"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="example.pro.Register" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.thinkappz.advancedtictactoe.RegisterActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="example.pro.RegisterActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.thinkappz.advancedtictactoe.SendRequest"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="example.pro.SendRequest" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.thinkappz.advancedtictactoe.PickFriendsActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="example.pro.PickFriendsActivity" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.thinkappz.advancedtictactoe.getFinishedGames"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="example.pro.getFinishedGames" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.thinkappz.advancedtictactoe.HomeScreen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="example.pro.HomeScreen" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/app_id" />
        <activity android:name="com.facebook.LoginActivity" />
        <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="example.pro" />
            </intent-filter>
        </receiver>
        <service android:name="com.thinkappz.advancedtictactoe.GCMIntentService" />
    </application>
</manifest>

GCMIntentService---->这个类文件在里面com.thinkappz.advancedtictactoe包,但我的 R.java 文件是在里面生成的example.pro。我不知道为什么。

package com.thinkappz.advancedtictactoe;

import javax.management.Notification;

public class GCMIntentService extends GCMBaseIntentService {

    private static final String TAG = "GCMIntentService";

    public GCMIntentService() {
        super(SENDER_ID);
    }

    /**
     * Method called on device registered
     **/
    @Override
    protected void onRegistered(Context context, String registrationId) {
        Log.i(TAG, "Device registered: regId = " + registrationId);
        displayMessage(context, "Your device registred with GCM");
        Log.d("NAME", GcmMainActivity.name);
        ServerUtilities.register(context, GcmMainActivity.name,
            GcmMainActivity.email, registrationId);
    }

    /**
     * Method called on device un registred
     * */
    @Override
    protected void onUnregistered(Context context, String registrationId) {
        Log.i(TAG, "Device unregistered");
        displayMessage(context, getString(R.string.gcm_unregistered));
        ServerUtilities.unregister(context, registrationId);
    }

    /**
     * Method called on Receiving a new message
     * */
    @Override
    protected void onMessage(Context context, Intent intent) {
        Log.i(TAG, "Received message");
        String message = intent.getExtras().getString("price");
        displayMessage(context, message);
        // notifies user
        generateNotification(context, message);
    }

    /**
     * Method called on receiving a deleted message
     * */
    @Override
    protected void onDeletedMessages(Context context, int total) {
        Log.i(TAG, "Received deleted messages notification");
        String message = getString(R.string.gcm_deleted, total);
        displayMessage(context, message);
        // notifies user
        generateNotification(context, message);
    }

    /**
     * Method called on Error
     * */
    @Override
    public void onError(Context context, String errorId) {
        Log.i(TAG, "Received error: " + errorId);
        displayMessage(context, getString(R.string.gcm_error, errorId));
    }

    @Override
    protected boolean onRecoverableError(Context context, String errorId) {
        // log message
        Log.i(TAG, "Received recoverable error: " + errorId);
        displayMessage(context,
            getString(R.string.gcm_recoverable_error, errorId));
        return super.onRecoverableError(context, errorId);
    }

    /**
     * Issues a notification to inform the user that server has sent a message.
     */
    private static void generateNotification(Context context, String message) {
        int icon = R.drawable.ic_launcher;
        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);
        String title = context.getString(R.string.app_name);
        Intent notificationIntent = new Intent(context, MainActivity.class);
        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0,
            notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        // Play default notification sound
        notification.defaults |= Notification.DEFAULT_SOUND;
        // notification.sound = Uri.parse("android.resource://" +
        // context.getPackageName() + "your_sound_file_name.mp3");
        // Vibrate if vibrate is enabled
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notificationManager.notify(0, notification);
    }
}

我也尝试过<service android:name="example.pro.GCMIntentService" />但随后它在注册时给我一个错误,说它无法实例化服务。


您正在使用com.google.android.gcm.GCMBroadcastReceiver来自 Google GCM 客户端库的广播接收器。此类期望意图服务位于应用程序的主包中(example.pro)但你的意图服务位于不同的包中 -com.thinkappz.advancedtictactoe。这就是接收者找不到服务的原因。

您应该移动GCMIntentService到您的应用程序的主包,或覆盖GCMBroadcastReceiver.

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

代码在向 GCM 注册时获取唤醒锁时卡住 的相关文章

  • Android 在打开应用程序时会广播吗?

    例如 如果我想知道Youtube何时打开 是否有与之相关的广播 我当然知道我可以轮询 logcat 消息来检查活动 但我可以通过广播来做到这一点吗 因为它会少得多的耗电 此链接似乎表明这是不可能的 如何跟踪 Android 中的应用程序使用
  • Android 上的 SVG 支持

    Android 支持 SVG 吗 有什么例子吗 最完整的答案是这样的 Android 2 x 默认浏览器本身不支持 SVG Android 3 默认浏览器支持 SVG 要将 SVG 支持添加到 2 x 版本的平台 您有两个基本选择 安装功能
  • 从 Android 代码设置的 SECRET_CODE

    我知道如何使用清单文件中的秘密代码 它与此源代码配合良好
  • 安卓定位不准确

    我正在尝试获取当前用户的位置 我试图重构我的代码以获得更好的结果 但我只是不断得到关于准确度的荒谬位置 它在 900 600 米之间 如何才能得到更好的结果 使其精度达到50m以内 这是我的代码 package com agam mapsl
  • 如何解决 Firebase AuthUi 中无法找到显式活动?

    使用 firebase UI 时 我无法找到显式活动类 com firebase ui auth KickoffActivity protected void onCreate Bundle savedInstanceState super
  • Android在排序列表时忽略大小写

    我有一个名为路径的列表 我目前正在使用以下代码对字符串进行排序 java util Collections sort path 这工作正常 它对我的 列表进行排序 但是它以不同的方式处理第一个字母的情况 即它用大写字母对列表进行排序 然后用
  • 如何为发布而不是调试创建密钥库?扑

    我按照使用此网站部署 flutter 的步骤进行操作https flutter io android release https flutter io android release 当我运行 flutter build apk 时出现此错
  • 出现错误错误:res/menu/mainMenu.xml:文件名无效:必须仅包含[a-z0-9_。]

    我是安卓新手 刚刚开始使用 我在 res 文件夹中创建了一个文件 menu mainMenu xml 但我得到了错误 Error res menu mainMenu xml invalid file name must contain on
  • Android onChange 事件未在 android 5 (Lollipop) 上的 chrome 历史记录的 contentObserver 中触发

    我注意到我的 chrome 历史记录和书签的 contentObservers 在 android lolipop 上不再触发 该代码在旧版本的 android 上完美运行 无论 chrome 版本如何 但在 Lollipop 上它不再运行
  • glTexImage2D: 之前出错:( 0x506 内部 0x1908 格式 0x1908 类型 0x1401

    当使用 Android Studio 运行模拟器时 我在模拟器屏幕上看不到任何内容 一切都是黑色的 我得到以下事件日志 模拟器 glTexImage2D 出错了 0x506 内部 0x1908 格式 0x1908 类型 0x1401 我已经
  • Android 应用程序中的 Eszett (ß)

    我的 res layout activity 文件中的德语 字符在我的应用程序中自动转换为 ss 即使我将语言和键盘设置为德语 它仍然不会显示 Android 中可以显示 吗 edit
  • 如何在 Android 模块中使用 FirebaseAuth

    我正在开发一个聊天库 我想在其中显示登录用户的对话 制作该库的原因是我想将其集成到多个项目中 我现在面临的问题是FirebaseAuth表示用户尚未登录 FirebaseAuth getInstance mFirebaseApp getCu
  • 画透明圆,外面填充

    我有一个地图视图 我想在其上画一个圆圈以聚焦于给定区域 但我希望圆圈倒转 也就是说 圆的内部不是被填充 而是透明的 其他所有部分都被填充 请参阅这张图片了解我的意思 http i imgur com zxIMZ png 上半部分显示了我可以
  • 使用 PhoneGap 使 Android 应用程序易于访问(对于残障人士)

    有人有过使用 PhoneGap 使 Android 应用程序可访问的经验吗 至少我们需要使我们的应用程序符合第 508 条规定 我尝试实现一些标准的辅助功能 文本框标签 向 div 添加标题属性等 但是 当在 Android 中使用 Tal
  • 在旋转时从错误的资源文件夹中提取可绘制对象

    在这里拉我的头发 因此 我正在使用一个具有多种类型的可绘制对象的应用程序 并且它们的结构如下 res Portrait resources drawable mdpi drawable hdpi drawable xhdpi Landsca
  • 按钮 - 单击时更改背景颜色

    我的活动中有 8 个按钮 我正在寻找的是 按钮具有默认背景 单击按钮时 背景颜色应更改为其他颜色 这部分非常简单 但是 当我单击任何其他按钮时 第一个按钮的背景颜色应该变回默认颜色 我知道这将使用 选择器状态 来完成 但我不太确定如何实现它
  • Android:监听状态栏通知

    有没有办法在状态栏被下拉时监听通知 1 用于检测状态栏变化 您可以注册一个监听器来获取系统UI可见性变化的通知 因此 要在您的活动中注册侦听器 Detecting if the user swipe from the top down to
  • Android 中循环事件的星期几和时间选择器

    我想创建一个控件 允许用户在我的 Android 活动中选择一周中的某一天 星期一 和一天中的某个时间 下午 1 00 找不到任何关于此的好帖子 好吧 我想我已经明白了 我只是不喜欢这个解决方案 因为我在一周中的某一天使用的微调器与时间选择
  • 尝试将 SQLite DB 从数据复制到 SD 卡

    我正在使用以下代码 该代码发布在 Stack Overflow 上的某个位置 并根据我的目的进行了修改 try File sd Environment getExternalStorageDirectory File data Enviro
  • 单元测试时 Android Studio 2.0 中测试状态终止且没有任何失败消息

    Issue 我昨天在 Ubuntu 上从 1 5 升级到了 Android Studio 2 0 当我在 Android Studio 2 0 中进行单元测试时 即使所有测试都已通过 它也会显示 终止测试 状态 有时它只显示部分测试通过 我

随机推荐

  • 如何在 pygame 中将旋转限制为设定的度数?

    我的问题与下面问题的答案相关 旋转一个矩形 如何将旋转限制在图中红色标记的区域 我尝试了各种方法但没有成功 代码始终将指针保留在其他区域 我修改后的代码如下 import pygame math base64 pygame init scr
  • 使用 htaccess 删除单个查询参数

    由于不值得在这里讨论的原因 Google 一直在为我的一个网站建立索引 其中 URL 中包含不必要的查询字符串 我想将我的 htaccess 文件修改为 301 将所有这些请求重定向到 URL 而无需查询字符串中不需要的部分 但保留查询字符
  • Bootstrap 表单:如何动态创建单选按钮的唯一名称

    这个问题是这个问题的后续问题one This JSfiddle体现了我想要实现的目标 Final Solution由 Scaramouche 提供 下面的函数动态地建立一个 列表 其中单选按钮每组四个 每个组都应该有一个唯一的名称 这使得可
  • 在哪里存储将在我的应用程序中使用的常量对象

    可以说我有一个item 其中有字段 属性 Location 平均值 可用性 我有10 15个items 我想要预定义其值 或者将其写入某处 然后加载到要使用的代码中 哪一个是最佳实践 这些将是常量 只是启动参数 在应用程序生命周期中不会被修
  • C结构的大小

    struct st1 int a 1 int b 3 int c 6 int d 3 s1 struct st2 char a 3 s2 int main printf d d sizeof s1 sizeof s2 getchar 我得到
  • 相互交织的范围如何造成“数据竞争”? [复制]

    这个问题在这里已经有答案了 The 锈书讨论了拥有多个读取器和对一个对象的多个可变引用作为可能导致问题的数据竞争情况 例如 这段代码 fn main let mut x 1 let r1 mut x r1 2 let r2 mut x r2
  • 如何使用 Python ElementTree 将新数据附加到现有 XML?

    我是Python新手 元素树 我有以下 XML 示例
  • Cassandra CQL 选择查询不返回以时间戳作为 clusterkey 的记录

    Cassandra CQL 使用复合键和簇键创建的表 当我尝试执行 select from 分区键时 我能够检索所有数据 并且它也适用于关系运算符 但是 当我使用等于 运算符和正确的值查询特定的簇键时 它返回 0 行 Table CREAT
  • Pickle Python 序列化

    通俗地说 什么是 序列化 为什么需要它 我读了维基百科条目 但仍然不明白 为什么需要将数据转换为位序列以将其存储在文件中 我特别关心使用Pythonpickle模块进行序列化 谢谢你的时间 您可以保存程序 特定对象 的状态 想象一下您有一个
  • 当手机进入空闲状态时,startscan() 10 分钟后有结果

    我试图每 2 分钟扫描一次 wifi 网络 我正在为此使用服务 当手机处于 活动 或 使用中 状态后startscan 叫我得到SCAN RESULTS AVAILABLE ACTION6秒后所以我可以定期扫描无线网络 但是 在手机在一定时
  • 如何从 MySql 数据库获取日期到 C# DateTime 对象?

    我有一个 MySQL 数据库 其中某个字段包含日期 如何将其转换为 C DateTime object 以及如何转换 C DateTime对象以便我可以将其插入数据库 你将需要适用于 NET 的 MySQL 连接器 如果您还没有的话 为了让
  • Git远程测试

    我习惯使用 Github 作为备份或中央存储库 并在本地进行开发和测试 现在我有一台远程测试机 并且希望能够将本地提交推送到远程 以便远程工作目录更新 从而允许我对内容运行测试 1 我发现的大多数设置遥控器的说明都是使用 bare init
  • 为什么“git show”不提供有关重定向标准输出的分支的信息?

    以下是两个带有结果示例的命令 git show commit 6f367e05cc6457fd0c0fc59fe0476db06cffb383 HEAD gt master tag v7 32 origin master origin HE
  • 如何在 WooCommerce 中禁用全局缺货

    我的网站每天都会添加新产品 为每个新产品和缺货产品持续选择 不允许缺货 选项是没有效率的 目前 数据库不断增长 包含 2 000 多种产品 我发现每天执行相同的流程很乏味 使用functions php文件 我可以实现一些php代码来禁止所
  • 将组计数列添加到 PySpark 数据帧

    我来自 R 和整洁宇宙由于 PySpark 具有卓越的 Spark 处理能力 我正在努力将某些概念从一个上下文映射到另一个上下文 特别是 假设我有一个如下所示的数据集 x y a 5 a 8 a 7 b 1 我想添加一列 其中包含每个的行数
  • Telerik MVC Grid 根据其他列值将列设为红色

    我有一个 Telerik MVC 网格 其中有两个字段 CustomerID and OrdersQuantity can go negative 我的网格看起来像这样 CustomerID OrdersQuantity 1 10 2 3
  • WinForms 中的自定义工具提示控件

    有没有一种简单的方法可以在 C WinForms 中创建和显示自定义工具提示控件 我目前的想法是 创建 Tooltip 的子类 重写OnPaint方法 设置它 作为父控件的工具提示 创建 form 和 show 的子类 手动 有什么想法吗
  • 如何用 igraph 绘制椭圆节点?

    SO 中似乎从未有人问过此类问题 但是 帮助页面igraph关于自定义节点形状相当模糊 有人可以提供自定义节点形状的完整示例吗igraph 你没说你用什么语言 所以我用R来回答 可以列出内置的形状shapes 不幸的是 椭圆不在其中 帮助页
  • 在新窗口中打开 HTML 元重定向

    我需要通过 HTML 元重定向网页并在新窗口中打开该页面 我怎样才能做到这一点
  • 代码在向 GCM 注册时获取唤醒锁时卡住

    我正在使用 GCM 为我的项目推送通知 但一直无法获取唤醒锁 日志消息 09 03 17 04 05 003 V GCMBroadcastReceiver 5772 onReceive com google android c2dm int