从GCMIntentService onRegistered()从来没有所谓的从来没有、GCMIntentService、onRegistered

2023-09-07 16:23:45 作者:小姐,不要離開我

我想我的注册GCM上的应用程序,但我不知道为什么我的应用程序是从来没有注册。 GCMRegistrar.register(这一点,SENDER_ID); 的调用,但onRegistered()从我GCMIntentService不会被调用。我不知道的为什么

I am trying to register my app on GCM but I don't know why my app is never registered. GCMRegistrar.register(this, SENDER_ID); is called but onRegistered() from my GCMIntentService is never called. I don't know WHY.

这是我的logcat

This is my Logcat

01-17 11:03:00.015: D/GCMRegistrar(3509): resetting backoff for com.abc.xyz.ui.activity
01-17 11:03:03.210: V/GCMRegistrar(3509): Registering app com.abc.xyz.ui.activity of senders 964256581311
01-17 11:03:06.070: V/GCMBroadcastReceiver(3509): onReceive: com.google.android.c2dm.intent.REGISTRATION
01-17 11:03:06.070: V/GCMBroadcastReceiver(3509): GCM IntentService class: com.abc.xyz.ui.activity.GCMIntentService
01-17 11:03:06.070: V/GCMBaseIntentService(3509): Acquiring wakelock

这是我的完整清单。

and this is my complete manifest

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

    <uses-sdk 
        android:minSdkVersion="11" android:targetSdkVersion="16"/>
    <uses-feature 
        android:name="android.hardware.usb.host"/>

    <!-- This app has permission to register and receive data message. -->
    <uses-permission
        android:name="com.google.android.c2dm.permission.RECEIVE" />

    <uses-permission 
        android:name="android.permission.INTERNET" />
    <uses-permission 
        android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission 
        android:name="android.permission.GET_TASKS" />
    <uses-permission 
        android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission
        android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission 
        android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission 
        android:name="android.permission.CALL_PHONE" /> 
    <uses-permission 
        android:name="android.permission.BLUETOOTH" />

    <!-- 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.

     NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
           where PACKAGE is the application's package name.
    -->
    <uses-permission
        android:name="com.abc.xyz.ui.activity.permission.C2D_MESSAGE" />   
    <permission
        android:name="com.abc.xyz.ui.activity.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />    
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" 
        android:theme="@android:style/Theme.Holo.Light" 
        android:name="com.abc.xyz.MyApplication" 
        android:allowBackup="false">
        <activity
            android:name=".StartupActivity"
            android:noHistory="true"
            android:label="@string/title_startup_screen" 
            android:configChanges="orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LoginActivity"
            android:windowSoftInputMode="stateAlwaysVisible|adjustResize"
            android:label="@string/title_login_screen"
            android:configChanges="orientation">
        </activity>
        //my other activity defination

        <!--
          BroadcastReceiver that will receive intents from GCM
          services and handle them to the custom IntentService.

          The com.google.android.c2dm.permission.SEND permission is necessary
          so only GCM services can send data messages for the app.
        -->
        <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.abc.xyz.ui.activity" />
            </intent-filter>
        </receiver>

        <!--
          Application-specific subclass of GCMBaseIntentService that will
          handle received messages.

          By default, it must be named .GCMIntentService, unless the
          application uses a custom BroadcastReceiver that redefines its name.
        -->
        <service android:name="com.abc.xyz.ui.activity.GCMIntentService" />

    </application>
</manifest>

我不知道什么是错的,为什么onRegistered()不会被调用。任何帮助将AP preciated。

I don't know what is wrong and why onRegistered() is never called. Any help will be appreciated.

推荐答案

我回答,因为粘贴code是手写的注释中:

I answer because pasting code is barely readable in comments:

我很想念您logcat的一些日志,供您建议服务甚至被称为。在注册时,我有这在我的logcat的:

I am missing some logs from your logcat that suggest your service is even called. I have this in my Logcat when registering:

GCMBroadcastReceiver  V  onReceive: com.google.android.c2dm.intent.REGISTRATION
GCMBroadcastReceiver  V  GCM IntentService class: com.package.android.app.GCMIntentService
GCMBaseIntentService  V  Acquiring wakelock
GCMBaseIntentService  V  Intent service name: GCMIntentService-DynamicSenderIds-1

特别是最后一行缺少,或者你忘了贴吧。你能确保你张贴的完整LogCat中?为 GCM 过滤器,以确保你没有错过的东西。

Especially the last line is missing or you have forgotten to paste it. Could you make sure that you posted the complete LogCat? Filter for GCM to make sure you didn't missed something.

更新

由于在评论中提到的OP,他用服务做多。这在某种程度上与GCM的功能,这分为两个服务,它的工作后干扰。经验教训:不要使用GCMIntentService为别的比GCM

As the OP mentioned in the comments, he used the service to do more. This somehow interfered with the GCM functionality and after separating this into two services it worked. Lessons learned: Don't use the GCMIntentService for anything else than GCM.