본문 바로가기

개발도구/aOS - 안드로이드 개발

[안드로이드] notification

http://rosaria1113.blog.me/112533451


MainActivity.java

package com.rosa.test.notification;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        setNotification();
    }
   
    private void setNotification(){
        NotificationManager notiMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification noti = new Notification(
                android.R.drawable.stat_notify_error,
                "rosa's notification test",
                System.currentTimeMillis());
               
        Intent intent = new Intent();
        intent.setClassName("com.rosa.test.service", "com.rosa.test.service.MainActivity");
       
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);


//        noti.flags |= Notification.FLAG_ONGOING_EVENT;  <- 이 flag를 추가하면  aggressive에 계속 icon이 떠있는다.
        noti.icon = R.drawable.icon;
        noti.setLatestEventInfo(this, "rosa's Title", "rosa's Content", contentIntent);
        notiMgr.notify(1, noti);
    }
}