2016-08-14 7 views
0

サーバーが特定の値を返すときに表示通知が必要です。私はアンドロイドで実行されているサービスを持っていて、タスクスケジューラはサーバにリクエストを送信するたびに実行されます。サーバが正の値を返すと、セルラディスプレイにメッセージを表示する必要があります。同様の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()); 
    } 
関連する問題