Notice
Recent Posts
Recent Comments
반응형
오늘도 공부
[펌]c2dm 관련 팁 본문
반응형
반응형
'Android > Tip&Tech' 카테고리의 다른 글
[팁]email에 파일첨부하기 (1) | 2011.05.31 |
---|---|
[팁]android bitmap을 불러와서 drag하는 예제 (0) | 2011.05.30 |
Working with XML on Android (0) | 2011.05.28 |
[android] Button의 color변경 (pressed, focus, default) 과 그라데이션 주기. (1) | 2011.05.27 |
[펌]SimpleCursorAdapter와 spinner 연결시 getSelectedItem() (0) | 2011.05.25 |
01.
if
(intent.getAction().equals(
02.
"com.google.android.c2dm.intent.RECEIVE"
)) {
03.
c2dm_msg = intent.getExtras().getString(
"msg"
);
04.
Toast toast = Toast.makeText(context,
"메시지 도착!\n"
+ c2dm_msg,
05.
Toast.LENGTH_SHORT);
06.
toast.setGravity(Gravity.TOP | Gravity.CENTER,
0
,
150
);
07.
toast.show();
08.
09.
nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
10.
PendingIntent pendingIntent = PendingIntent.getActivity(
11.
context,
0
,
new
Intent(context, C2dmTest.
class
),
0
);
12.
String ticker = c2dm_msg;
13.
String title =
"test"
;
14.
String text = c2dm_msg;
15.
16.
//화면 켜짐 유무 체크
17.
KeyguardManager km = (KeyguardManager)context.getSystemService(Context.KEYGUARD_SERVICE);
18.
// Create Notification Object
19.
if
(GetClassName(context).equals(
"c2.dm.C2dmTest"
) && !km.inKeyguardRestrictedInputMode()){}
20.
else
if
(km.inKeyguardRestrictedInputMode()){
21.
22.
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
23.
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK ,
"test"
);
24.
wl.acquire();
25.
Notification notification =
new
Notification(R.drawable.icon1,ticker, System.currentTimeMillis());
26.
notification.defaults |= (Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
27.
notification.flags = notification.flags | Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONGOING_EVENT ;
28.
29.
notification.setLatestEventInfo(context,title, text, pendingIntent);
30.
nm.notify(
1234
, notification);
31.
nm.wait(
5000
);
32.
wl.release();
33.
34.
35.
}
형식으로 전 OnReceive 내에서 사용했습니다.
Context만 끌고오면 문제없이 사용할 수 있으실겁니다.