无法启动GCM意图服务

3

大家好,我在尝试使用Google GCM技术,但是我的GCM网络服务在注册事件上无法唤醒,我知道我做错了什么,但我还是搞不清楚具体是哪里出了问题...

这是我的清单文件:

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

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

    <!-- GCM connects to Internet Services. -->
    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.ACCESS_WIFI_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="com.dmx.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.dmx.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:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

        <!-- Splash Screen -->
        <activity android:name="com.dmx.ui.ActivitySplashScreen" >

        </activity>

        <!-- ActivitySplashScreen Screen -->
        <activity android:name="com.dmx.ui.ActivityLoginRegister" >
        </activity>

        <!-- Login Screen -->
        <activity android:name="com.dmx.ui.ActivityLogin" >
        </activity>


        <!-- Broadcasr Reciever Declaration For Incoming Messages -->
        <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="com.dmx" />
            </intent-filter>
        </receiver>

        <!-- GCM Service Declaration -->
        <service android:name="com.dmx.logic.services.GCMIntentService" ></service>
    </application>

</manifest>

以及logcat输出 -

04-18 06:53:39.561: D/PowerManagerService(2959): [api] handleWakeLockDeath : release WakeLock : PARTIAL_WAKE_LOCK              'GCM_LIB' (uid=10218, pid=31431, ws=null) (elapsedTime=110364)
04-18 06:53:42.316: W/ActivityManager(2959): Unable to start service Intent { act=com.tmc.logic.services.GCMIntentService } U=0: not found
04-18 06:53:43.821: I/PCWCLIENTTRACE_PushUtil(28180): getPushTypeList : [SPP, GCM]
04-18 06:53:44.826: V/GCMBroadcastReceiver(31887): GCM IntentService class: com.tmc.GCMIntentService
04-18 06:53:44.831: W/ActivityManager(2959): Unable to start service Intent { act=com.google.android.c2dm.intent.REGISTRATION flg=0x10 pkg=com.tmc cmp=com.tmc/.GCMIntentService (has extras) } U=0: not found

我已经反复检查,发现服务嵌套在应用程序中,并尝试通过意图启动它......但它就是不起作用.....有什么帮助吗?

1个回答

9
你正在使用的是com.google.android.gcm.GCMBroadcastReceiver广播接收器。该类期望意图服务类位于应用程序的主包中 - 在你的情况下是com.dmx。但由于你将意图服务放在了com.dmx.logic.services中,因此找不到它。
你可以在logcat中看到它期望GCMIntentServicecom.tmc中:

04-18 06:53:44.826: V/GCMBroadcastReceiver(31887): GCM IntentService class: com.tmc.GCMIntentService 04-18 06:53:44.831: W/ActivityManager(2959): Unable to start service Intent { act=com.google.android.c2dm.intent.REGISTRATION flg=0x10 pkg=com.tmc cmp=com.tmc/.GCMIntentService (has extras) } U=0: not found

你应该将意图服务类移动到主包中或更改广播接收器以在其当前位置查找它。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接