2012-07-23 67 views
0

我有一個問題,當我GCMIntentService被調用時,拋出一個異常:GCMIntentService轉換異常

java.lang.ClassCastException:com.test.test.GCMIntentService不能 投地android.content.BroadcastReceiver

但是我的課並延長GCMBaseIntentService,其實我的構建「結束」以及(超級(SENDER_ID);而不問題通過)和問題就來了退出構造函數時,我懷疑一個內部類嘗試當投射我的擴展類的新創建的實例。如果需要的話

參考

代碼:

package com.adk.test; 

import java.io.IOException; 
import java.util.ArrayList; 
import java.util.List; 

import org.apache.http.HttpResponse; 
import org.apache.http.NameValuePair; 
import org.apache.http.client.ClientProtocolException; 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.entity.UrlEncodedFormEntity; 
import org.apache.http.client.methods.HttpPost; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.apache.http.message.BasicNameValuePair; 

import android.app.Notification; 
import android.os.Bundle; 
import android.support.v4.app.NotificationCompat; 
import android.support.v4.app.NotificationCompat.Builder; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.Context; 
import android.content.Intent; 
import utilities.Logd; 

import com.google.android.gcm.GCMBaseIntentService; 
import com.google.android.gcm.GCMConstants; 
import com.google.android.gcm.GCMRegistrar; 

public class GCMIntentService extends GCMBaseIntentService { 

    private final String LOG_TAG = "Test"; 
    private final static String senderID = "66610078X85X"; 


    public GCMIntentService(){ 
     super("66610078X85X"); 
     Logd.i(LOG_TAG, "GCM passed"); 
    } 


    @Override 
    protected void onError(Context arg0, String errorID) { 
     Logd.e(LOG_TAG, errorID, null); 
    } 


    @Override 
    protected void onMessage(Context arg0, Intent intent) { 
     enviarNotificacion(arg0, intent); 

    } 

    @Override 
    protected void onRegistered(Context arg0, String deviceID) { 
     Registrar(arg0, deviceID);  
     Logd.i(LOG_TAG, "Registered"); 
    } 

    @Override 
    protected void onUnregistered(Context arg0, String arg1) { 
     Logd.i(LOG_TAG, "Unregistered"); 

    } 

} 

回答

1

考慮通過一個GCMBroadcastReceiver到任何你傳遞的GCMIntentService來。您不應該需要繼承並覆蓋該名稱,因爲它看起來像您的意向服務已具有the right name

+0

我不會傳遞給任何東西:SI只需撥打GCMRegistrar.register (act,SENDER_ID);和構造函數被調用,我認爲GCMRegistrar試圖施放它。 – 2012-07-23 02:29:09

+0

有趣。你有沒有打電話給GCMBroadcastReceiver.checkManifest()? – Iain 2012-07-23 02:34:26

+0

是的,我打電話給GCMRegistrar.checkManifest(),我應該發佈清單嗎? – 2012-07-23 02:36:11

0

的異常指示框架試圖在訪問您的GCMIntentService:

com.test.test.GCMIntentService 

但你的源代碼中有設置爲包名稱:

package com.adk.test; 

我想改變你的包名com.test.test應該管用。

或者,如果你更喜歡使用com.adk.test.GCMIntentService,然後修改您的AndroidManifest.xml的GCM接收器:

<receiver android:name="com.adk.test.GCMIntentService" .... />