2014-10-29 46 views
0

我试图使我的自定义通知类似于这一个 enter image description here 我发现了一堆类似的问题在这里和互联网上的例子,但没有人帮助我。在android中的大自定义通知

这里是我的代码:

 RemoteViews bigView = new RemoteViews(mContext.getApplicationContext().getPackageName(), R.layout.notification_playback); 

     Intent i = new Intent(MainActivity.ACTION_PLAYER, null, mContext, MainActivity.class); 
     i.putExtra("CURRENT_TRACK", t); 
     i.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

     PendingIntent pi = PendingIntent.getActivity(mContext, 0, i, 0); 

     Notification n = new NotificationCompat.Builder(mContext) 
      .setContentTitle(t.getName()) 
      .setContentText(t.getArtistName()) 
      .setContentIntent(pi) 
      .setSmallIcon(R.drawable.ic_notification) 
      .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_launcher)) 
      .setOngoing(true) 
      .setContent(bigView) 
      .setWhen(System.currentTimeMillis()) 
      .build(); 

     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) 
      n.bigContentView = bigView; 

     NotificationManager notifyMgr = (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE); 
     notifyMgr.notify(0, n); 

它出现在默认的大小,成为大小我只后,就可以长按预期。

是否可以在不长时间使其立即变大尺寸?如果有,我该怎么办? 谢谢!

+0

这是[另一个问题](http://stackoverflow.com/questions/21237495/create-custom-big-notifications),可能会帮助你。 – 2014-10-29 13:20:21

+0

@TheRealBenjamin谢谢,但我已经试过了。它说'技巧不是使用setStyle(),而是在构建它之后手动设置Notification的bigContentView字段,但正如你所看到的,我正在做这件事。 – 2014-10-29 13:25:18

+1

http://stackoverflow.com/questions/18367631/change-notification-layout – Praveen 2014-10-29 13:29:53

回答

0

所以,我想通了。 如果通知显示为通知,则通知显示为已展开。否则,用户可以将其向下拖动以展开,以显示常规高度。 为了使它出现在通知的顶部,您可以使用.setPriority(Notification.PRIORITY_MAX)Builder

+0

顺便说一句,如果你没有设置优先级和设备插入到你的电脑最有可能的连接作为媒体设备通知将在顶部所以你会永远把它看成没有扩大。 – 2014-10-30 17:46:35