我有2个remoteViews


通知内容
通知代码(我认为这行不通)


我尚未包含2的代码。一旦内容正常工作,我将尝试2。

下面的代码

    Intent intent = new Intent(this, HomeScreen.class);
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.pickupnotification);
    RelativeLayout pickupNotificationLayout = (RelativeLayout)this.getLayoutInflater().inflate(R.layout.pickupnotification, null) ;
    TextView title = (TextView)pickupNotificationLayout.findViewById(R.id.title) ;
    TextView countDown = (TextView)pickupNotificationLayout.findViewById(R.id.countDown) ;
    TextView from = (TextView) pickupNotificationLayout.findViewById(R.id.from) ;
    TextView to = (TextView) pickupNotificationLayout.findViewById(R.id.to) ;
    contentView.apply(this, pickupNotificationLayout);

    title.setText("Siddharth" + "2km -> 20km");
    countDown.setText("-1:29") ;
    from.setText("FROM 2:00pm 14th Jan 2013, Some address") ;
    to.setText("TO 4:00pm 14th Jan 2013 Some address") ;
    Notification noti = new NotificationCompat.Builder(this).setContent(contentView)
            .setSmallIcon(R.drawable.notification_logo)
            .setContentIntent(pIntent)
            .build();
    NotificationManager notificationManager =
      (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    noti.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, noti);

最佳答案

您不必多次那样夸大所有视图,我相信您认为放置文本的位置与框架认为放置文本的位置并不相同。使用RemoteViews上可用的方法,用于填写内容的代码应该看起来更像这样。

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.pickupnotification);

contentView.setTextViewText(R.id.title, "Siddharth" + "2km -> 20km");
contentView.setTextViewText(R.id.countDown, "-1:29");
contentView.setTextViewText(R.id.from,
        "FROM 2:00pm 14th Jan 2013, Some Address");
contentView.setTextViewText(R.id.to,
        "TO4:00pm 14th Jan 2013 Some address");

Notification noti = new NotificationCompat.Builder(this)
        .setContent(contentView)
        .setSmallIcon(R.drawable.notification_logo)
        .setContentIntent(pIntent)
        .build();


显然,您还将希望对股票代码视图进行类似的处理。

关于android - Android通知内容不会显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14421933/

10-10 21:10
查看更多