2015-10-21 97 views
0

我正嘗試在片段內使用AppCompat創建通知。 我創造什麼都看不到。安卓 - 沒有出現通知

代碼:

private void createNotification() 
{ 
    Context context = getActivity().getApplicationContext(); 
    Intent notificationIntent = new Intent(context, MainActivity.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context); 
    builder.setContentIntent(contentIntent) 
      .setSmallIcon(R.drawable.ymk_ya_logo) 
      .setAutoCancel(false) 
      .setContentTitle("notify") 
      .setContentText("test"); 

    Notification notification = builder.build(); 

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); 
    notificationManager.notify(777, notification); 
} 

回答

0

試着改變你的最後一位到這個代替:

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

notificationManager.notify(0, builder.build());