내 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>
왜 이런 일이 발생했는지에 대한 아이디어는 크게 감사하겠습니다.
당신은'ClassCastException'을 가지고 있습니다. onRegistered()에서 85 행에 무엇을 캐스팅하려고합니까? – Karakuri
그건 나에게 혼란 스러웠다 ... 나의 GCMIntentService 파일은 85 줄도 길지 않다. – Chris