在Android中显示两个班轮通知

时间:2016-05-19 13:43:48

标签: android user-interface push-notification notifications android-notifications

这非常特定于默认情况下向用户显示的通知行数        这是其他应用程序和显示两行通知的方式            Google plus notification

System Notification

虽然我的通知只是一个班轮 我怎么能通知两个班轮

这是我的代码。

   Intent intent = new Intent(RegisterActivity.this, RegisterActivity.class);
    intent.putExtra(NotificationUtility.NOTIFICATION_TYPE, getString(R.string.notification_type_register));
    intent.putExtra(MainActivityList.LAUNCH_ACTIVITY, MainActivityList.LAUNCH_MAIN_LIST);
    PendingIntent contentIntent = PendingIntent.getActivity(RegisterActivity.this, 0,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);

 NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setPriority(NotificationCompat.PRIORITY_MAX);

    if(title != null){
        bigTextStyle.setBigContentTitle(title);
        builder.setContentTitle(title);
    }
    if (display_message != null){
        bigTextStyle.bigText(display_message);
        builder.setContentText(display_message);
    }

    bigTextStyle.setSummaryText(summaryText);
    builder.setStyle(bigTextStyle);

    builder.setAutoCancel(true);
    builder.setDefaults(Notification.DEFAULT_ALL);
    builder.setContentIntent(contentIntent);
    builder.setDeleteIntent(cancelIntent);


    Notification notification = builder.build();
    // Add as notification
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(notificationId, notification);

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码,它适用于我

       RemoteViews myView = new RemoteViews(context.getPackageName(),
                R.layout.notifybaralert);

        myView.setTextViewText(R.id.tv_NotifyAlertTitle, msgTitle);
        myView.setTextViewText(R.id.tv_NotifyAlertMsg, msgBody);
        notify.setSmallIcon(R.drawable.ic_launcher); //to set icon that appers on the bar
        notify.setAutoCancel(true);
        notify.setContentIntent(pintent);
        notify.setContent(myView);
        notify.setContentTitle(msgTitle); //to set title that appears on the bar

此处myView是RemoteView类型。

notifybaralert的xml如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3" >

        <ImageView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight=".5"
            android:adjustViewBounds="true"
            android:src="@drawable/ic_launcher" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/tv_NotifyAlertTitle"
                style="@style/NotificationTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Babaji Shivram"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/tv_NotifyAlertMsg"
                style="@style/NotificationText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxLines="8"
                android:text="TextView" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

它提供的通知与您提供的图像完全相同。

希望这会有所帮助:)