小编eim*_*mer的帖子

Google GCMIntentService实例化

可能重复:
Android RuntimeException:无法实例化服务

尝试启动并运行GCM,但我的设备正在发送注册请求,但没有从GCM服务器返回任何响应.下面我包括了我的清单和GCMIntentService定义,以及我对GCM服务器注册的调用.我一直在盯着它,所以我可能会遗漏一些明显的东西,如果是的话,我道歉.

欢迎所有想法!

这是我的清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="PACKAGE"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <permission android:name="PACKAGE.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="PACKAGE.permission.C2D_MESSAGE" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <service android:name=".GCMIntentService" 
            android:enabled="true"/>

        <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="PACKAGE.GCMIntentService" />
            </intent-filter>
        </receiver>


        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

这是我的GCMIntentService来处理来自GCM的返回:

import com.google.android.gcm.GCMBaseIntentService;
import android.content.Context;
import android.content.Intent;
import android.util.Log; …
Run Code Online (Sandbox Code Playgroud)

android google-cloud-messaging

16
推荐指数
3
解决办法
3万
查看次数

标签 统计

android ×1

google-cloud-messaging ×1