You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Titanium Android推送通知配置失败:GCM SenderId获取异常求助

解决Titanium Android推送通知retrieveDeviceToken()报错问题

你遇到的核心问题是缺少GCM Sender ID的配置,而你之前创建的"Client ID"其实就是这个Sender ID,只是文档没明确说明它的配置位置。结合你的报错和代码,我给你一步步梳理解决方案:

1. 理解报错原因

控制台的Failed receiving GCM SenderId. Getting GCM SenderId failed. Max retry time reaches.错误,本质是Titanium的ti.cloudpush模块无法找到用于GCM(现在是FCM)推送的项目标识——也就是你保存的那个Client ID。

2. 在tiapp.xml中补全Android配置

你提到没添加任何Android清单配置,这正是问题所在。需要把以下配置添加到你的tiapp.xml的<android>标签内(注意替换其中的包名和Client ID):

<android xmlns:android="http://schemas.android.com/apk/res/android">
    <manifest>
        <!-- 推送所需权限 -->
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.WAKE_LOCK"/>
        <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
        <!-- 替换成你的应用包名(可在tiapp.xml的<id>标签中找到) -->
        <permission android:name="com.yourpackage.name.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
        <uses-permission android:name="com.yourpackage.name.permission.C2D_MESSAGE"/>

        <application>
            <!-- GCM Sender ID配置,填入你的Client ID -->
            <meta-data android:name="com.google.android.gms.gcm.defaultSenderId" android:value="@string/gcm_sender_id"/>
            <resources>
                <string name="gcm_sender_id">YOUR_CLIENT_ID_HERE</string>
            </resources>

            <!-- 推送相关的接收器和服务 -->
            <receiver
                android:name="com.google.android.gms.gcm.GcmReceiver"
                android:exported="true"
                android:permission="com.google.android.c2dm.permission.SEND">
                <intent-filter>
                    <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
                    <category android:name="com.yourpackage.name"/>
                </intent-filter>
            </receiver>
            <service
                android:name="appcelerator.cloud.push.PushService"
                android:exported="false">
                <intent-filter>
                    <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
                </intent-filter>
            </service>
            <service
                android:name="appcelerator.cloud.push.RegistrationIntentService"
                android:exported="false"/>
        </application>
    </manifest>
</android>

关键注意点:

  • 把com.yourpackage.name替换成你应用的实际包名
  • 把YOUR_CLIENT_ID_HERE替换成你之前创建的那个"Client ID"

3. 确认模块配置

确保你已经在tiapp.xml的<modules>标签内正确引入了ti.cloudpush模块:

<modules>
    <module platform="android">ti.cloudpush</module>
</modules>

4. 你的代码无需修改

你提供的代码片段是正确的,配置完成后,再次调用CloudPush.retrieveDeviceToken()就能正常获取设备令牌了。

额外提示

  • 如果你使用的是较新版本的Titanium,可检查SDK管理器中Google Play服务是否已正确安装(ti.cloudpush通常会自动集成相关依赖,但偶尔需要手动确认)
  • 确认你的Client ID是从Google Cloud控制台的项目中正确复制的,不要包含多余字符或空格

内容的提问来源于stack exchange,提问作者Nuibb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:16:11