C2DM과 Notification 사용시 막히는 부분이 있어서 이렇게 질문 드립니다.

 

01.public class C2dm_BroadcastReceiver extends BroadcastReceiver {          // -------- 1번
02. 
03.NotificationManager mNotiManager;
04.public static String registration_id = null;
05.static String c2dm_name = "";
06.static String c2dm_msg = "";
07. 
08. 
09.public void onReceive(Context context, Intent intent) {
10. 
11.mNotiManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);          // ---------- 2번
12. 
13.if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION")) {
14. 
15.handleRegistration(context, intent);
16. 
17. 
18.else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {         // ---------- 3번
19. 
20.c2dm_name = intent.getExtras().getString("name");
21.c2dm_msg = intent.getExtras().getString("msg");
22. 
23.System.out.println("c2dm_msg======>"+c2dm_msg);
24. 
25. 
26.Toast toast = Toast.makeText(context, c2dm_name+"님 으로부터의 메시지\n"+c2dm_msg, Toast.LENGTH_LONG );
27.toast.setGravity( Gravity.TOP | Gravity.CENTER, 0150 );
28.toast.show();
29. 
30.Notification noti = new Notification(R.drawable.btn_notread, "쪽지가 왔어요~!", System.currentTimeMillis());
31. 
32.noti.defaults |= Notification.DEFAULT_SOUND;
33.noti.defaults |= Notification.DEFAULT_VIBRATE;
34. 
35.noti.flags |= Notification.FLAG_AUTO_CANCEL;
36. 
37.mNotiManager.notify(1, noti);
38.}
39.}
40. 
41.private void handleRegistration(Context context, Intent intent) {
42. 
43.registration_id = intent.getStringExtra("registration_id");
44. 
45.System.out.println("registration_id====>"+registration_id);
46. 
47.if (intent.getStringExtra("error") != null) {
48.Log.v("C2DM_REGISTRATION",">>>>>" "Registration failed, should try again later." "<<<<<");
49.else if (intent.getStringExtra("unregistered") != null) {
50.Log.v("C2DM_REGISTRATION",">>>>>" "unregistration done, new messages from the authorized sender will be rejected" "<<<<<");
51.else if (registration_id != null) {
52. 
53.SharedPreferences pref = context.getSharedPreferences("reg_id"0);
54.SharedPreferences.Editor editor = pref.edit();
55. 
56.editor.putString("reg_id", registration_id);
57. 
58.editor.commit();
59. 
60.System.out.println("registration_id complete!!");
61.}
62.}
63. 
64.}

 

 C2DM을 이용해 3번에서 수신후 토스트 메시지는 뜨는데, 이것 대신 위와 같은 방식을 이용해 notification으로 알려주려고 하니까 2번에서 문제가 발생하고.. 1번의 extends BroadcastReceiver를 extends Activity로 바꾸자니 2번의 문제는 해결이 되지만 onReceive를 이용 할 수가 없고..  여기서 어떻게 해야 notification으로 알려줄 수 있을까요??