Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- 예외처리
- Android
- HTML
- 생성자
- struts2
- OGNL
- Java
- 오버로딩
- paint
- mybatis
- 국제화
- 에러페이지
- layout
- Spring
- 클래스
- oracle
- 메소드
- Graphic
- Menu
- 안드로이드
- JavaScript
- Eclips
- 전화걸기
- JSP
- 기본
- 배열
- AWT
- 어노테이션
- 이클립스
- 메서드
Archives
- Today
- Total
note
Notify 알림 메세지 본문
DDMS에 접근해서
이렇게 입력합니다(한글은 안됨)
위에 알림메세지가 기존과 다르게 나타남
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/notify"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="클릭하면 5초 후에 알림 메시지가 전달됩니다." />
<Button
android:id="@+id/cancel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="알림 메세지를 중단합니다." />
</LinearLayout>
package kr.android.notify;
//알림 메세지
import android.app.Activity;
import android.os.Bundle;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import java.util.Timer;
import java.util.TimerTask;
public class NotifyDemo extends Activity {
private static final int NOTIFY_ME_ID = 1337;// 식별하기 위한
private Timer timer = new Timer();// 스레드 응용
private int count = 0; // 카운팅하기 위한
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.notify);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
TimerTask task = new TimerTask() {
public void run() {
notifyMe();
}
};
// 위에 문장(TimerTask)먼저 실행되지 않고 지금 이문장이 실행되면서 task를 5초 뒤에 실행
timer.schedule(task, 5000);
}
});
btn = (Button) findViewById(R.id.cancel);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
NotificationManager mgr = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
mgr.cancel(NOTIFY_ME_ID);
}
});
}
private void notifyMe() {
final NotificationManager mgr = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.red_ball, "알림 메시지!",
System.currentTimeMillis());
/*=-=-=-=-=-=-=전달인자=-=-=-=-=-=-=-=-
Context context : 실행중인 Activity 객체
int requestCode : 현재 사용되지 않음
Intent intent : 실행시킬 Activity 정보를 가지고 있는 Intent객체
FLAG_CANCEL_CURRENT : 이전에 생성한 PendingIntent는 취소 새롭게 생성
FLAG_NO_CREATE : 현재 생성된 PendingIntent 반환
FLAG_ONE_SHOT : 생성된 PendingIntent는 단 한번만 사용가능
FLAG_UPDATA_CURRENT: 이미 생성된 PendingIntent가 있다면 Intent의 내용 변경
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Activity 가 아닐경우에는 PendingIntent 를 사용*/
PendingIntent i = PendingIntent.getActivity(this, 0,
new Intent(this,NotifyMessage.class), 0);
note.setLatestEventInfo(this, "알림 제목", "알림 메세지 본문입니다.", i);
//카운트는 초기화 되지 않아서 제거한뒤 다시 추가하여도 그전에 숫자까지 카운팅됨
note.number = ++count;
mgr.notify(NOTIFY_ME_ID, note);
}
}
package kr.android.notify;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class NotifyMessage extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView txt = new TextView(this);
txt.setText("알림 메세지!");
setContentView(txt);
}
}
AndroidManifest.xml 에 접근해서 Application에 Activity를 등록해 줘야 합니다(권한 게시물 참고)
나중에 브로드캐스트 리시버에 사용하기 위한(?) 초기단계
setLatestEventInfo 에 대한 영역(첫번째 자바코드 63번 라인)
'Android > 기본' 카테고리의 다른 글
| News Service 주기적으로 데이터 가지고 오기 (0) | 2012.01.18 |
|---|---|
| SMSReceiver (BroadcastReceiver사용) (0) | 2012.01.18 |
| 전화걸기2 컨텍트 프로바이더contact (0) | 2012.01.17 |
| 안드로이드 전화걸기 (0) | 2012.01.17 |
| 구글맵 사용하여 위도 경도값 직접입력해서 보기 (0) | 2012.01.17 |