2016-07-26 12 views
0

私のアプリでGCMプッシュ通知を使用しています。しかし、私はテキストメッセージとアイコンを取得していません。白い背景のみを表示します。通知テキストはAndroidの通知バーに表示されませんか?

これは高度でいただければ幸いです。このissue.anyヘルプを解決するために私を助けてください私のアプリ

public void onMessageReceived(String from, Bundle data) { 

     //Getting the message from the bundle 
     String message = data.getString("message"); 
     //Displaying a notiffication with the message 
     String body = null; 
     String title = null; 
     try{ 
      String notificationJSONString = data.getString("notification"); 
      //then you can parse the notificationJSONString into a JSON object 
      JSONObject notificationJSON = new JSONObject(notificationJSONString); 
      body = notificationJSON.getString("body"); 
      title = notificationJSON.getString("title"); 

     }catch (Exception e){ 
      e.printStackTrace(); 
     } 
     // sendNotification(message); 
     sendNotification(body,title); 
    } 

    //This method is generating a notification and displaying the notification 
    private void sendNotification(String message,String title) { 
     Intent intent = new Intent(this, NavigationDrawerActivity.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     intent.putExtra("firsttab","notify"); 
     int requestCode = 0; 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT); 
     Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); 
     NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this) 
       // .setSmallIcon(R.mipmap.philips_launcher) 
       .setSmallIcon(getNotificationIcon()) 
       .setContentTitle(title) 
       .setContentText(message) 
       .setAutoCancel(true) 
       .setSound(sound) 
       .setColor(Color.parseColor("#0089C4")) 
       .setStyle(inboxStyle) 
       // .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) 
       .setContentIntent(pendingIntent); 
     /* if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
      builder.setSmallIcon(R.drawable.icon_transperent); 
     } else { 
      builder.setSmallIcon(R.drawable.icon); 
     }*/ 

     NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(0, noBuilder.build()); //0 = ID of notification 
    } 

    private int getNotificationIcon() { 
     boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP); 
     return useWhiteIcon ? R.drawable.not_icon : R.mipmap.philips_launcher; 
    } 

に通知を受信するための当社のコードです。 私は多くのコードをstackoverflowで与えられていますが、同じ問題に直面しています。

+0

GCMの投稿リクエストは何ですか? –

+0

このようなメッセージ受信機能でデータを取得 – Anand

+0

バンドル[{通知=バンドル[{サウンド2 = 1、e = 1、ボディ=ヘイイ、アイコン=、バッジ= 1、 サウンド=デフォルト、タイトル=フィリップスCORTA-NEW通知、振動= 1}]、collapse_key = com.philips.ordertracker}] – Anand

答えて

0

メッセージ文字列で通知を受け取ると、さらに解析する必要はありません。 文字列message = data.getString( "message"); あなたはそのメッセージに付随するタイトルがない場合は、あなたのアプリケーションのベースでタイトルを与えることができます

0

このコードを変更して、それを試してみてください。 最後に.Build();が見つかりませんでした。

から:へ

NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this) 
      // .setSmallIcon(R.mipmap.philips_launcher) 
      .setSmallIcon(getNotificationIcon()) 
      .setContentTitle(title) 
      .setContentText(message) 
      .setAutoCancel(true) 
      .setSound(sound) 
      .setColor(Color.parseColor("#0089C4")) 
      .setStyle(inboxStyle) 
      // .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) 
      .setContentIntent(pendingIntent); 

:通知メッセージの白い背景の問題が知られており、固定されている

NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this) 
      // .setSmallIcon(R.mipmap.philips_launcher) 
      .setSmallIcon(getNotificationIcon()) 
      .setContentTitle(title) 
      .setContentText(message) 
      .setAutoCancel(true) 
      .setSound(sound) 
      .setColor(Color.parseColor("#0089C4")) 
      .setStyle(inboxStyle) 
      // .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) 
      .setContentIntent(pendingIntent).build(); 
+0

返信いただきありがとうございます。 – Anand

0

、修正が間もなくリリースされなければなりません。別のオプションは、データメッセージを使用して、onMessageReceivedコールバックで通知の作成を管理することです。