How to Implement the Deprecated Methods of Notification

How to implement the deprecated methods of Notification

This is how i ended up to the solution:

if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {

notification = new Notification(icon, text, time);
notification.setLatestEventInfo(this, title, text, contentIntent); // This method is removed from the Android 6.0
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(NOTIFICATION, notification);
} else {
NotificationCompat.Builder builder = new NotificationCompat.Builder(
this);
notification = builder.setContentIntent(contentIntent)
.setSmallIcon(icon).setTicker(text).setWhen(time)
.setAutoCancel(true).setContentTitle(title)
.setContentText(text).build();

mNM.notify(NOTIFICATION, notification);
}

Edit:

The above solution works. Still, since, NotificationCompat.Builder class was introduced, we can skip the if condition for checking that compares current API version. So, we can simply remove the if...else condition, and go with:

NotificationCompat.Builder builder = new NotificationCompat.Builder(
this);
notification = builder.setContentIntent(contentIntent)
.setSmallIcon(icon).setTicker(text).setWhen(time)
.setAutoCancel(true).setContentTitle(title)
.setContentText(text).build();
mNM.notify(NOTIFICATION, notification);

The constructor notification is deprecated

You're attempting to use the constructor for Notification which is deprecated as of API 11. Meaning it isn't supported any longer and should not be used. use Notification.Builder instead https://developer.android.com/reference/android/app/Notification.Builder.html

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

You currently have the following :

Notification notification = new Notification(icon, message, when);

This constructor is deprecated in favor of the Notification.Builder which would look like the following :

Notification notification = new Notification.Builder(context)
.setContentText(message)
.setSmallIcon(icon)
.setWhen(when)
.build();

In Android, how do I remove a notification variable from being deprecated?

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

Why does it say deprecated for a method when its the only one I can use for the selected API-level?

So why am I getting the deprecated warning even though its the only one I can and should use?

Because your build target is API Level 16 or higher, where this method is deprecated.

One might think that the warning/docs should adapt to the minSdkLevel, not the highets one

In that case, one would be incorrect. Deprecation has nothing to do with minSdkVersion, any more than it would in standard Java outside of Android (where deprecation exists and minSdkVersion does not).

Moreover, you should be using the Android Support package's version of Notification.Builder (called NotificationCompat.Builder, since the native one does not exist in API Level 10, which your manifest indicates that you are trying to support. build() should exist on NotificationCompat.Builder and work on all your desired API levels.

Are silent remote push notifications deprecated in iOS 11?

Use this

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler

or for Swift

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

}

The deprecated one is

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo


Related Topics



Leave a reply



Submit