2013-04-25 1 views
0

GCMIntentService 파일의 onRegistered 기능에 도달하면 내 Android 앱을 새로 설치할 때 충돌이 발생합니다. GCM 등록이 성공적이며 다음에 앱을 열 때 GCM 등록 ID를 검색 할 수 있지만 사용자가 처음 열면 GCM 등록이 중단되는 것을 원하지 않습니다. GCMIntentServce가 등록 성공 후 Android 앱이 다운 됨

내가 등록을 요구하려면이 옵션을 사용 :이 로그 캣 여기

V/GCMBaseIntentService(9604): Releasing wakelock 
W/dalvikvm(9604): threadid=10: thread exiting with uncaught exception (group=0x40020950) 
E/AndroidRuntime(9604): FATAL EXCEPTION: IntentService[GCMIntentService-##########-1] 
E/AndroidRuntime(9604): java.lang.ClassCastException: android.app.Application 
E/AndroidRuntime(9604): at com.myfile.app.GCMIntentService.onRegistered(GCMIntentService.java:85) 
E/AndroidRuntime(9604): at com.google.android.gcm.GCMBaseIntentService.handleRegistration(GCMBaseIntentService.java:296) 
E/AndroidRuntime(9604): at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:197) 
E/AndroidRuntime(9604): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59) 
E/AndroidRuntime(9604): at android.os.Handler.dispatchMessage(Handler.java:99) 
E/AndroidRuntime(9604): at android.os.Looper.loop(Looper.java:123) 
E/AndroidRuntime(9604): at android.os.HandlerThread.run(HandlerThread.java:60) 
D/dalvikvm(9604): GC_FOR_MALLOC freed 3478 objects/299784 bytes in 815ms 

의 충돌 부분 내 GCMIntentService 파일 여기

public class GCMIntentService extends GCMBaseIntentService { 

    private static final String LOG_TAG = "GCM"; 

    public GCMIntentService() { 
     super("###############"); // use my GCM ID 
     // TODO Auto-generated constructor stub 
     Log.i(LOG_TAG, "GCMIntentService constructor called"); 
    } 

    @Override 
    protected void onError(Context arg0, String errorId) { 
     // TODO Auto-generated method stub 
     Log.i(LOG_TAG, "GCMIntentService onError called: " + errorId); 
    } 

    @Override 
    protected void onMessage(Context arg0, Intent intent) { 
     // TODO Auto-generated method stub 
     Log.i(LOG_TAG, "GCMIntentService onMessage called"); 
     Log.i(LOG_TAG, "Message is: " + intent.getStringExtra("message")); 
    } 

    @Override 
    protected void onRegistered(Context arg0, String registrationId) { 
     // TODO Auto-generated method stub 
     Log.i(LOG_TAG, "GCMIntentService onRegistered called"); 
     Log.i(LOG_TAG, "Registration id is: " + registrationId); 

     // ! ! ! CRASHES HERE ! ! ! 

    } 

    @Override 
    protected void onUnregistered(Context arg0, String registrationId) { 
     // TODO Auto-generated method stub 
     Log.i(LOG_TAG, "GCMIntentService onUnregistered called"); 
     Log.i(LOG_TAG, "Registration id is: " + registrationId); 
    } 
} 

GCMRegistrar.checkDevice(this); 
GCMRegistrar.checkManifest(this); 
String regId = GCMRegistrar.getRegistrationId(this); 
if (regId.equals("")) { 
    GCMRegistrar.register(this, getResources().getString(R.string.gcmToken)); 
} 

것입니다

은 매니페스트 파일

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


    <!-- B1 - BSG DEV --> 

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

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.VIBRATE"/> 

    <!-- Google Cloud Messaging --> 
    <permission android:name="com.myfile.app.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
    <uses-permission android:name="com.myfile.app.permission.C2D_MESSAGE" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <!-- Google Cloud Messaging --> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/icon1" 
     android:label="@string/app_name" > 


     <activity 
      android:name="com.myfile.app.MainActivity" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait" 
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

     <activity android:name="com.myfile.app.myclass" android:screenOrientation="portrait"/> 


      <!-- Google Cloud Messaging --> 
     <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="com.myfile.app" /> 
      </intent-filter> 
     </receiver> 
     <service android:name=".GCMIntentService" /> 
     <!-- Google Cloud Messaging --> 

     </application> 


</manifest> 

왜 이런 일이 발생했는지에 대한 아이디어는 크게 감사하겠습니다.

+0

당신은'ClassCastException'을 가지고 있습니다. onRegistered()에서 85 행에 무엇을 캐스팅하려고합니까? – Karakuri

+0

그건 나에게 혼란 스러웠다 ... 나의 GCMIntentService 파일은 85 줄도 길지 않다. – Chris

답변

0

매니페스트에 리시버 및 인 텐트 서비스를 등록하셨습니까?

예 :

가지고

안드로이드-SDK-WINDOWS \ 엑스트라 구글 \ \ GCM \ GCM 클라이언트 \ DIST : 당신은 다음 경로에서 올바른 항아리를 얻을 수 있습니다

<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="PACKAGE_NAME" /> 
       </intent-filter> 
      </receiver> 
      <service android:name=".GCMIntentService"></service> 
+0

나는 그것들을 가지고있다. Manifest 파일을 원래 게시물에 추가했습니다. 어쩌면 나는 거기에 섞여있는 것을 가지고있다 ... – Chris

+0

나는 또한 ClassCastException을 보았다. 올바른 gcm.jar 라이브러리를 사용하고 있습니까? – Andres

+0

"올바른"gcm.jar이 있는지 어떻게 알 수 있습니까? – Chris

관련 문제