代码之家  ›  专栏  ›  技术社区  ›  Christopher Treanor

在Android中,如何删除不推荐使用的通知变量?

  •  0
  • Christopher Treanor  · 技术社区  · 11 年前

    如何从代码中删除弃用?我似乎因此受到了警告。删除文本是“新通知”和setLatestEventInfo?上面写着“这种方法在API级别11中被弃用了?这意味着什么?”? 请帮忙。我该如何解决这个问题?

    @SuppressWarnings("deprecation")
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // TODO Auto-generated method stub
        Toast.makeText(this, "OnStartCommand()", Toast.LENGTH_SHORT).show();
        NotificationManager notificationmanager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        Intent notificationintent = new Intent(this, Reminder_2.class);
        PendingIntent pendingintent = PendingIntent.getActivity(this, 0, notificationintent, 0);
        int icon=R.drawable.ic_launcher;
        long when=System.currentTimeMillis();
        @SuppressWarnings("deprecation")
        Notification notification=new Notification (icon, "There's a message", when);
        notification.setLatestEventInfo(this, "Title here", "Content here.", pendingintent);
        notificationmanager.notify(033, notification);
        return super.onStartCommand(intent, flags, startId);
    }
    
    2 回复  |  直到 11 年前
        1
  •  2
  •   ashatte HM.Rajjaz    11 年前

    一直以来 deprecated ,这意味着它已被标记为在未来版本的Android中删除,或者已经引入了更好的标准/替代方案。文档建议改用Notification.Builder:

    Notification noti = new Notification.Builder(mContext)
             .setContentTitle("New mail from " + sender.toString())
             .setContentText(subject)
             .setSmallIcon(R.drawable.new_mail)
             .setLargeIcon(aBitmap)
             .build();
    

    查看文档: http://developer.android.com/reference/android/app/Notification.Builder.html

        2
  •  2
  •   Community CDub    8 年前

    这是什么意思?

    在编写计算机软件、其标准或文档的过程中,弃用是一种应用于软件功能的状态,表示应避免使用这些功能,通常是因为它们已被取代。尽管不推荐使用的功能仍保留在软件中,但使用这些功能可能会引发建议替代做法的警告消息,并且不推荐使用可能表明该功能将来将被删除。为了提供向后兼容性,功能会被弃用,而不是立即删除,并让使用过该功能的程序员有时间让他们的代码符合新标准。

    来源: Here

    我该如何解决这个问题?

    正如您在 documentation of Notification ,

    Notification(int icon, CharSequence tickerText, long when)
    

    可以替换为 Notification.Builder