'Push'에 해당되는 글 1건

  1. 2014.11.20 Android 푸시
2014. 11. 20. 13:23

출처 : http://raidparty.net/xe/index.php?mid=android_tech&document_srl=1200&listStyle=viewer#viewSource

 

 

NotificationManager mangager = (NotificationManager)getSystemService( Context.NOTIFICATION_SERVICE ) ;

 

// 상태바에 표시될 아이콘, Notification이 뜰 때 상태바에 표시될 제목, 확장상태바의 알림을 시간순으로 정렬

Notification notification = new Notification( R.drawable.a, "알림", System.currentTimeMillis( ) ) ;

 

Context context = getApplicationContext( ) ;

Intent it = new Intent( this, noti.class ) ;

 

// 이동될 액티비티

PendingIntent launchIntent = PendingIntent.getActivity( context, 0, it, 0 ) ;

 

// context, 확장 상태바에 표시될 제목, 내용

notification.setLatestEventInfo(context, "알림제목", "알림내용", launchIntent ) ;

// Notification의 아이디

mangager.notify( 1, notification ) ;

 

 

 

실행되는 액티비티에 다음 코드를 작성하면 노티 작동이 멈춤

NotificationManager mangager = (NotificationManager)getSystemService( Context.NOTIFICATION_SERVICE ) ;

mangager.cancel( 1 ) ;  // 정지할 Notification의 아이디 

 

Notification에 알림음 넣기

1. 기본 알림음 넣기

notification.defaults = (Notification.DEFAULT_SOUND ) ;

 

2. 커스텀 알림음 넣기

Uri ringUri = Uri.fromFile( new File( "음악파일경로" ) ) ;

notification.sound = ringUri ;

 

 

Notification에 진동(vibrate) 넣기

1. 기본 진동(vibrate) 넣기

notification.defaults = ( Notification.DEFAULT_VIBRATE) ;

 

2. 커스텀 진동(vibrate) 넣기

notification.vibrate = new long[ ]{ 1000, 1000, 1000, 1000, 1000 } ;

( 순서대로 대기시간, 진동시간, 대기시간, 진동시간 이런 식으로 반복이다.) 

 

 

# 기본 알림음과 기본 진동을 같이 사용하고 싶으면 

    notification.defaults = (Notification.DEFAULT_SOUND  Notification.DEFAULT_VIBRATE)  ;

 

# 사용자가 확인할때까지 무한 반복하고 싶으면 

   notification.flags = Notification.FLAG_INSISTENT ;

 

붗빛 깜박이기

notification.ledARGB = Color.RED ;

notification.ledOffMS = 0 ;

notification.ledOnMS = 1 ;

notification.flags = Notification.FLAG_SHOW_LIGHTS;

Posted by 작은0악마