android - 无法启动 GCM Intent 服务

标签 android push-notification android-service google-cloud-messaging

大家好,我遇到了谷歌 GCM,但出于某种原因,我的 GCM 互联网服务拒绝在注册事件中唤醒 - 我知道我做错了什么,我只是想不通是什么......

这是我的 list 文件 -

<?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

我已经仔细检查了该服务是否嵌套在应用程序中,并尝试通过 intent 启动它......它只是不起作用......任何帮助???

最佳答案

您正在使用 com.google.android.gcm.GCMBroadcastReceiver 广播接收器。该类期望 Intent 服务类位于您应用程序的主包中 - 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

您应该将您的 Intent 服务类移动到主包,或者更改广播接收器以在其当前位置查找它。

关于android - 无法启动 GCM Intent 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23147155/

相关文章:

java - Android Espresso 拖放错误注入(inject)事件

Android 调试(重新设计的 APK 和 waitForDebugger)

android - 从 FCM 通知访问、打开或编辑 Web View

android - Dagger2 服务中的 RuntimeException AndroidInjection.inject

android - 如何在循环中重复使用相同的java Message参数

java - 获取非 Activity 类的 onActivityResult (Android)

java - AsyncTask 中执行参数的类型安全替代方案

android - RIM OS (BIS)、IOS和android中Push功能的区别

javascript - 使用云函数 firebase、JavaScript 进行通知

android - 如何知道应用程序何时从后台删除?