唯一的解决方案是创建自己的RemoteView,如下所示:
首先,一个自定义布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/status_bar_latest_event_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/list_selector_background">
<ImageView
android:id="@+id/big_icon"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp"
android:scaleType="fitCenter"
/>
<TextView
android:id="@+id/title"
android:text="sometitlestringfromresources"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_alignBottom="@+id/big_icon"
android:layout_toRightOf="@+id/big_icon"
android:layout_marginLeft="15dp"/>
<ImageView
android:id="@+id/big_picture"
android:layout_width="match_parent"
android:layout_height="192dp"
android:layout_marginTop="64dp"
android:scaleType="fitCenter" //This scale will show your picture without crop
/>
而且RemoteView的实现:
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
RemoteViews views;
views = new RemoteViews(getPackageName(), R.layout.custom_notification);
views.setImageViewBitmap(R.id.big_picture, bitmap);
views.setImageViewBitmap(R.id.big_icon, BitmapFactory.decodeResource(getResources(), R.drawable.your_24x24dp_brand_icon));
views.setTextViewText(R.id.title, message);
myNotification.bigContentView = views;
}
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(randomInt, myNotification);
其中myNotification是您的通知生成器,randomInt是我自己实现的避免重叠通知的方法(检查是否需要替换通知或生成多个通知)。
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(100);
就是这样。可能有点不太规范,但它能用。我将把这个漏洞留给Google,如果我收到一些回应,我会更新此内容。