【发布时间】:2014-10-29 13:15:58
【问题描述】:
我正在尝试使我的自定义通知类似于此通知 我在 SO 上找到了一堆类似的问题和互联网上的示例,但没有人帮助我。
这是我的代码:
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);
它以默认大小显示,并在长按后变成我期望的大小。
是否可以在不长按的情况下立即使其变大?如果是这样,我该怎么做? 谢谢!
【问题讨论】:
-
这里是another question,可能会对您有所帮助。
-
@TheRealBenjamin 谢谢,但我已经尝试过了。它说
The trick is not to use setStyle() but manually set the bigContentView field of the Notification after building it,但正如你所见,我做得对。
标签: android notifications