2

我有 2 个远程视图

  1. 对于通知内容
  2. 对于通知自动收报机(我认为这行不通)

我没有包含 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); 

通知向下滑动图片

4

1 回答 1

1

你不应该多次夸大你所有的观点,我相信你认为文本被放置在哪里和框架认为文本被放置在哪里是不一样的。您填写内容的代码应该看起来更像这样,使用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();

显然,您也希望对股票代码视图执行类似的模式。

于 2013-01-20T05:32:28.517 回答