GCM 키등록이 안되서 질문올립니다. onRegistered 이 함수가 호출이 되질 않는것 같구요
이유는 다음 코드(registerGCM 함수) 를 지닌 클래스가 GCMBaseIntentService 를 상속받은 GCMIntentService 클래스와 같은 패키지가 아닐 경우에만 키등록이 안되더라구요. 꼭 반드시 같은 패키지 내에 있어야하는 이유가 뭔가요??
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
registerGCM();
}
private void registerGCM(){
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog().build());
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
GCMManager.regId = String.valueOf(regId);
if (regId.equals("")) {
GCMRegistrar.register(this, "99225203282");
} else {
Log.e("reg_id", regId);
}
}
}
다음은 같은 패키지에 있을 경우입니다.

다음은 GCMIntentService 에서 키 등록시 호출 되는 함수 입니다.

다음은 manifest입니다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testgcm"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<!-- GCM Service -->
<permission
android:name="com.example.testgcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.testgcm.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.testgcm.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>
<!-- GCM -->
<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"/>
</intent-filter>
</receiver>
<service android:name="com.example.testgcm.GCMIntentService"></service>
</application>
</manifest>
현재 위 manifest 파일에서 볼 수 있듯이 mainActivity 와 GCMIntentService 클래스가 같은 패키지에 있는 경우입니다.
물론 이 경우에는 키 등록도 되고 잘 작동하지만 GCMIntentService 패키지를 다른걸로 변경하고 <service android:name = "????"></service> 를 변경된 패키지이름으로 바꿔주면 키등록이 안되네요. 어떻게 해결할 수 있죠?
퍼미션 주는 부분도 변경된 패키지 이름으로 바꿔도 봤는데 그 경우에는 아에 그냥 빨간 에러가 발생하더라구요