2015-07-31 3 views
2

У меня есть простой метод, который onclick() из Button должен генерировать уведомление о состоянии. Но я не знаю, почему он не отображается.уведомление о статусной строке не отображается

public void showNotification() 
{ 


    NotificationManager mNotificationManager = 
       (NotificationManager) getSystemService(this.NOTIFICATION_SERVICE); 


     NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(MainActivity.this); 

     mBuilder.setContentTitle("Status Bar Multiline"); 
     mBuilder.setContentText("Hello ! I am there and i am captains of the sky ,I got something work"); 
     mNotificationManager.notify(10,mBuilder.build()); 

} 

этот метод я называю onclick() из в Button

ответ

0

попробовать это

Notification notification = new Notification(icon, tickerText, when); 
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 
. 
. 
. 
notificationManager.notify(100, notification); 




long when = System.currentTimeMillis(); 
0

вы можете попробовать это

NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle("Test notification").setContentText("this is test application.").setSmallIcon(R.drawable.ic_launcher); 

TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 
stackBuilder.addNextIntent(new Intent(this, MainActivity.class)); 



PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 
builder.setContentIntent(resultPendingIntent); 



NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); 
notificationManager.notify(1, builder.build()); 
0

Для андроида, чтобы поставить уведомление в строке состояния , вы должны установить для него маленький значок. то есть,

mBuilder.setSmallDrawable(R.mipmap.ic_launcher); //Use your icon here. I am using the app's default icon 
mBuilder.setContentTitle("Status Bar Multiline"); 
mBuilder.setContentText("Hello ! I am there and i am captains of the sky ,I got something work"); 
mNotificationManager.notify(10,mBuilder.build()); 
0

попробовать это:

Notification.Builder nb = new Notification.Builder(GCMIntentService.this); 

     nb.setSmallIcon(mSmallIconRes) 
      .setContentTitle(mContentTitle) 
      .setContentText(mContentText) 
      .setStyle(new Notification.BigTextStyle().bigText(mContentText)) 
      .setTicker(mTicker) 
      .setLargeIcon(result == null ? mDefaultLargeIcon : result) 
      .setSubText("") 
      .setContentInfo(mContentInfo)    
      .setWhen(mWhen) 
      .setSound(alarmSound); 

     Intent notificationIntent = new Intent(GCMIntentService.this, dogs_online.class); 
     nb.setAutoCancel(true); 

     notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(GCMIntentService.this, 0, notificationIntent, 0); 
     nb.setContentIntent(pendingIntent); 

     NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);   
     super.onPostExecute(result);