Android通知内容不会出现

时间:2013-01-20 05:22:45

标签: android android-notifications

我有2个remoteViews

  1. 获取通知内容
  2. 通知自动收报机(我觉得这不行)
  3. 我没有包含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); 
    

    notification swipe down image

1 个答案:

答案 0 :(得分: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();

显然,您也希望使用自动收报机视图执行类似的模式。