2016-11-24 57 views

回答

0

這是我會怎麼做,只是使用NotificationCompat.Builder。

// create RemoteViews 
     final RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.remoteview_notification); 

     remoteViews.setImageViewResource(R.id.remoteview_notification_icon, R.mipmap.future_studio_launcher); 

     remoteViews.setTextViewText(R.id.remoteview_notification_headline, "Headline"); 
     remoteViews.setTextViewText(R.id.remoteview_notification_short_message, "Short Message"); 

     remoteViews.setTextColor(R.id.remoteview_notification_headline, getResources().getColor(android.R.color.black)); 
     remoteViews.setTextColor(R.id.remoteview_notification_short_message, getResources().getColor(android.R.color.black)); 

// build notification 
     NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(UsageExampleTargetsAndRemoteViews.this) 
       .setSmallIcon(R.mipmap.future_studio_launcher) 
       .setContentTitle("Content Title") 
       .setContentText("Content Text") 
       .setContent(remoteViews) 
       .setPriority(NotificationCompat.PRIORITY_MIN); 

     final Notification notification = mBuilder.build(); 

// set big content view for newer androids 
     if (android.os.Build.VERSION.SDK_INT >= 16) { 
      notification.bigContentView = remoteViews; 
     } 

     NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); 
     mNotificationManager.notify(NOTIFICATION_ID, notification); 
相關問題