【问题标题】:Android Notification Content wont show upAndroid 通知内容不会显示
【发布时间】:2013-01-20 13:44:16
【问题描述】:

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

【问题讨论】:

    标签: android android-notifications


    【解决方案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();
    

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

    【讨论】:

    • 谢谢。我会尝试并报告。但我修复了我当前的问题,noti.contentView = contentView ;。我想知道为什么 setContent 不起作用。
    • 工作!!你是对的,我不需要膨胀。但我仍然无法让布局完全显示它隐藏在选项卡(通知/快速设置)后面。
    • 抱歉,我试图用一块石头击中 2 只鸟。我已经从这个问题中删除了另一个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 1970-01-01
    • 2016-07-06
    • 1970-01-01
    相关资源
    最近更新 更多