7

アプリをGCMに登録しようとしていますが、アプリが登録されない理由がわかりません。GCMRegistrar.register(this, SENDER_ID);が呼び出されますが、GCMIntentServiceからのonRegistered()が呼び出されることはありません。なぜかわかりません。

これは私の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

これが私の完全なマニフェストです

    <?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()が呼び出されないのかわかりません。どんな助けでもありがたいです。

4

2 に答える 2

10

私は別の投稿で何が問題なのかを理解しました。私のGCMIntentServiceクラスは、マニフェストで次のように定義されています。

<service android:name="MY_PACKAGE.gcm.GCMIntentService" />

このクラスをルートパッケージに配置したくなかったため、代わりにMY_PACKAGE.gcmに配置しました。これにより問題が発生するようで、ドキュメントに記載されているように、

次のインテントサービスを追加します

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

したがって、ルートパッケージに移動すると、機能しました。GCMIntentServiceSubclassを任意の場所に配置し、別の名前を付ける別の方法があります。この他の投稿に示されているように、GCMBroadcastReceiverをサブクラス化し、マニフェストとサブクラスで変更を行う必要があります。

于 2013-04-03T15:16:02.880 に答える
2

貼り付けコードはコメントでほとんど読めないので、私は答えます:

あなたのサービスが呼び出されていることを示唆するいくつかのログがあなたのlogcatから欠落しています。登録時にLogcatにこれがあります:

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何かを見逃していないことを確認するためにフィルタリングします。

アップデート

OPがコメントで述べたように、彼はサービスを使用してさらに多くのことを行いました。これはどういうわけかGCM機能を妨害し、これを2つのサービスに分割した後は機能しました。学んだ教訓:GCM以外の目的でGCMIntentServiceを使用しないでください。

于 2013-01-18T11:01:47.547 に答える