Domanda

How do I remove the deprecation from my code? I seem to be getting warnings because of this. Strike-through texts were "new Notification" and setLatestEventInfo? It says "This method is deprecated in API level 11? What does that mean? Pleas help. How do I solve this?

@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);
}
È stato utile?

Soluzione

It's been deprecated, which means it has been flagged for removal in future versions of Android, or that a better standard/alternative has been introduced. The documentation recommends using Notification.Builder instead:

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

Take a look at the documentation: http://developer.android.com/reference/android/app/Notification.Builder.html

Altri suggerimenti

What does that mean?

In the process of authoring computer software, its standards or documentation, deprecation is a status applied to software features to indicate that they should be avoided, typically because they have been superseded. Although deprecated features remain in the software, their use may raise warning messages recommending alternative practices, and deprecation may indicate that the feature will be removed in the future. Features are deprecated—rather than immediately removed—in order to provide backward compatibility, and give programmers who have used the feature time to bring their code into compliance with the new standard.

source : Here

How do I solve this?

As you can found in the documentation of Notification,

Notification(int icon, CharSequence tickerText, long when)

can be replace with Notification.Builder

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top