2016-08-14 8 views
0

서버에서 특정 값을 반환 할 때 표시 알림이 필요합니다. 나는 서비스가 안드로이드 및 서버에 요청을 보낼 때마다 taskschedule 실행, 서버가 긍정적 인 가치를 반환 할 때 나는 Celsular 디스플레이에 메시지를 표시하고, whatsapp (디스플레이 아이콘 및 디스플레이 알림)과 유사한 메시지를 수신해야합니다. 누구나 샘플을 가지고 있습니까?Android 애플리케이션에서 알림을 표시하는 방법은 무엇입니까?

PendingIntent resultPendingIntent = PendingIntent.getActivity(
    this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

하지만 내 응용 프로그램을 서비스로 실행 :

나는이 시도.

+0

를 사용하세요? – Shaishav

답변

0

당신은 통지를 구축하기위한 코드를 Using Service to run background and create notification

private void processStartNotification() { 
     // Do something. For example, fetch fresh data from backend to create a rich notification? 

     final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
     builder.setContentTitle("Scheduled Notification") 
       .setAutoCancel(true) 
       .setColor(getResources().getColor(R.color.colorAccent)) 
       .setContentText("This notification has been triggered by Notification Service") 
       .setSmallIcon(R.drawable.notification_icon); 

     PendingIntent pendingIntent = PendingIntent.getActivity(this, 
       NOTIFICATION_ID, 
       new Intent(this, NotificationActivity.class), 
       PendingIntent.FLAG_UPDATE_CURRENT); 
     builder.setContentIntent(pendingIntent); 
     builder.setDeleteIntent(NotificationEventReceiver.getDeleteIntent(this)); 

     final NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); 
     manager.notify(NOTIFICATION_ID, builder.build()); 
    } 
관련 문제