안녕하세요.
지금 Google 오픈 소스보면서 공부중에 있는 초보입니다..ㅠ
혼자서 GCM을 공부할라고 하는데 에러가.. 나옵니다.
찾고 찾아봐도 어떻해 해야하는지 잘 모르겠어 이렇게 질문을 드립니다. ㅠㅠㅠ
소스는 GCMIntentService, MainActivity, Manifest, 에러 순입니다..
package com.example.sdfaadad;
import java.util.Iterator;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gcm.GCMBaseIntentService;
public class GCMIntentService extends GCMBaseIntentService {
private static final String tag = "GCMIntentService";
private static final String PROJECT_ID = "340156353694";
public static String SEND_ID;
// 구글 api 페이지 주소 [https://code.google.com/apis/console/#project:긴 번호]
// #project: 이후의 숫자가 위의 PROJECT_ID 값에 해당한다
// public 기본 생성자를 무조건 만들어야 한다.
public GCMIntentService() {
this(PROJECT_ID);
}
public GCMIntentService(String project_id) {
super(project_id);
}
/** 푸시로 받은 메시지 */
@Override
protected void onMessage(Context context, Intent intent) {
Bundle b = intent.getExtras();
Iterator<String> iterator = b.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
String value = b.get(key).toString();
Log.d(tag, "onMessage. " + key + " : " + value);
}
}
/** 에러 발생시 */
@Override
protected void onError(Context context, String errorId) {
Log.d(tag, "onError. errorId : " + errorId);
}
/** 단말에서 GCM 서비스 등록 했을 때 등록 id를 받는다 */
@Override
protected void onRegistered(Context context, String regId) {
Log.d(tag, "onRegistered. regId : " + regId);
}
/** 단말에서 GCM 서비스 등록 해지를 하면 해지된 등록 id를 받는다 */
@Override
protected void onUnregistered(Context context, String regId) {
Log.d(tag, "onUnregistered. regId : " + regId);
}
}
package com.example.sdfaadad;
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gcm.GCMRegistrar;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_item);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (equals(""))
GCMRegistrar.register(this, "340156353694");
else
Log.d("==============", regId);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sdfaadad"
android:versionCode="1"
android:versionName="1.0" >
<!-- GCM 관련 퍼미션 -->
<permission
android:name="com.example.sdfaadad.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.sdfaadad.permission.C2D_MESSAGE" />
<!-- GCM 받기 -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM을 받으려면 구글 계정 필요 -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- 메시지 받을 때 wake up 하기 위해 -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- 네트워크 접속 권한 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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>
<!-- GCM 리시버에서 돌리는 서비스 -->
<service android:name=".GCMIntentService" /> <!-- 서비스명 변경하면 안됨 -->
</application>
</manifest>
07-23 21:47:57.207: I/dalvikvm(1966): Could not find method com.google.android.gcm.GCMRegistrar.checkDevice, referenced from method com.example.sdfaadad.MainActivity.onCreate
07-23 21:47:57.207: W/dalvikvm(1966): VFY: unable to resolve static method 6102: Lcom/google/android/gcm/GCMRegistrar;.checkDevice (Landroid/content/Context;)V
07-23 21:47:57.207: D/dalvikvm(1966): VFY: replacing opcode 0x71 at 0x0008
07-23 21:47:57.567: D/AndroidRuntime(1966): Shutting down VM
07-23 21:47:57.567: W/dalvikvm(1966): threadid=1: thread exiting with uncaught exception (group=0xb4a23ba8)
07-23 21:47:57.587: E/AndroidRuntime(1966): FATAL EXCEPTION: main
07-23 21:47:57.587: E/AndroidRuntime(1966): Process: com.example.sdfaadad, PID: 1966
07-23 21:47:57.587: E/AndroidRuntime(1966): java.lang.NoClassDefFoundError: com.google.android.gcm.GCMRegistrar
07-23 21:47:57.587: E/AndroidRuntime(1966): at com.example.sdfaadad.MainActivity.onCreate(MainActivity.java:17)
07-23 21:47:57.587: E/AndroidRuntime(1966): at android.app.Activity.performCreate(Activity.java:5231)
07-23 21:47:57.587: E/AndroidRuntime(1966): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-23 21:47:57.587: E/AndroidRuntime(1966): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
07-23 21:47:57.587: E/AndroidRuntime(1966): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
07-23 21:47:57.587: E/AndroidRuntime(1966): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-23 21:47:57.587: E/AndroidRuntime(1966): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-23 21:47:57.587: E/AndroidRuntime(1966): at android.os.Handler.dispatchMessage(Handler.java:102)
07-23 21:47:57.587: E/AndroidRuntime(1966): at android.os.Looper.loop(Looper.java:136)
07-23 21:47:57.587: E/AndroidRuntime(1966): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-23 21:47:57.587: E/AndroidRuntime(1966): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 21:47:57.587: E/AndroidRuntime(1966): at java.lang.reflect.Method.invoke(Method.java:515)
07-23 21:47:57.587: E/AndroidRuntime(1966): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-23 21:47:57.587: E/AndroidRuntime(1966): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-23 21:47:57.587: E/AndroidRuntime(1966): at dalvik.system.NativeStart.main(Native Method)
07-23 21:48:03.047: I/Process(1966): Sending signal. PID: 1966 SIG: 9