3

我对GCM服务有问题。Android GCM在ICS上工作,但不在姜饼上

我的应用程序在android> = 4.0设备上正常工作,但没有(例如)在姜饼上工作。

我认为这个问题是清单,但似乎是正确

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

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

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

    <!-- 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" /> 

     <!-- 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="@style/AppTheme" > 
     <uses-library android:name="com.google.android.maps"/> 
       <activity 
      android:name=".RegisterActivity" 
      android:label="@string/app_name" > 
     </activity> 
     <activity 
      android:name="com.example.maptest.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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


      <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="MapTest" /> 
    </intent-filter> 

    </receiver> 

       <service android:name="com.example.maptest.GCMIntentService" android:enabled="true"/> 
    </application> 


</manifest> 

而且我的课

public class GCMIntentService extends GCMBaseIntentService { 

    private static final String TAG = "GCMIntentService"; 

    public GCMIntentService() { 
     super(SENDER_ID); 
     Log.d(TAG,"CREATO IL Servizio"); 
    } 

    /** 
    * Method called on device registered 
    **/ 
    @Override 
    protected void onRegistered(Context context, String registrationId) { 
     Log.i(TAG, "Device registered: regId = " + registrationId); 
     displayMessage(context, "Your device registred with GCM"); 
     Log.d("NAME", MainActivity.name); 
     ServerUtilities.register(context, MainActivity.name, MainActivity.email, registrationId); 
     /*TODO*/ 
     MainActivity.regId=registrationId; 
    } 

    /** 
    * Method called on device un registred 
    * */ 
    @Override 
    protected void onUnregistered(Context context, String registrationId) { 
     Log.i(TAG, "Device unregistered"); 
     displayMessage(context, getString(R.string.gcm_unregistered)); 
     ServerUtilities.unregister(context, registrationId); 
    } 

    /** 
    * Method called on Receiving a new message 
    * */ 
    @Override 
    protected void onMessage(Context context, Intent intent) { 
     Log.i(TAG, "Received message"); 
     String message = intent.getExtras().getString("price"); 

     displayMessage(context, message); 
     // notifies user 
     generateNotification(context, message); 
    } 

    /** 
    * Method called on receiving a deleted message 
    * */ 
    @Override 
    protected void onDeletedMessages(Context context, int total) { 
     Log.i(TAG, "Received deleted messages notification"); 
     String message = getString(R.string.gcm_deleted, total); 
     displayMessage(context, message); 
     // notifies user 
     generateNotification(context, message); 
    } 

    /** 
    * Method called on Error 
    * */ 
    @Override 
    public void onError(Context context, String errorId) { 
     Log.i(TAG, "Received error: " + errorId); 
     displayMessage(context, getString(R.string.gcm_error, errorId)); 
    } 

    @Override 
    protected boolean onRecoverableError(Context context, String errorId) { 
     // log message 
     Log.i(TAG, "Received recoverable error: " + errorId); 
     displayMessage(context, getString(R.string.gcm_recoverable_error, 
       errorId)); 
     return super.onRecoverableError(context, errorId); 
    } 

} 

在logcat的没有它的显示。

有人可以帮助我吗? 谢谢!

回答

2

如果这是你的com.example.maptest包的名字,它应该是您在清单文件中声明在

<category android:name="MapTest" /> 

的一个是这样的

<category android:name="com.example.maptest" /> 
+0

感谢的!现在我认为服务工作,但回答我的错误“失踪帐户”在AVD。为什么?我正在使用带有Google Apis的AVD机器:-( – Name29 2013-04-05 07:14:01

+0

在早期的Android版本中,您需要使用手机上的帐户登录才能使推送消息正常工作:“必须至少有一个登录Google帐户设备运行的版本低于Android 4.0.4“ - http://developer.android.com/google/gcm/gcm.html#arch – 2013-04-05 09:00:09

+1

在C2DM的Beta版本中,您必须拥有一个gmail帐户才能对自己进行身份验证到用于推送消息的服务,还必须在实际设备或模拟器中安装谷歌播放应用程序。 – 2013-04-05 22:37:55

相关问题