I m trying to run an android source code in eclipse. The targetSdkVerison for this app is 5 . I m totally new to android and have installed the latest api’s ( Android 4.1) . In some part of the code I m getting errors such as
public void hideNotification(Service context)
{
context.setForeground(false);// error: The method setForeground(boolean) is undefined for the type Service
getNotificationManager(context).cancel(NOTIF_PLAYING);
}
public void showNotification(Service context, long songId)
{
context.startForeground(NOTIF_PLAYING, newNotification(context, songId));//error :Call requires API level 5 (current min is 3): android.app.Service#startForeground
}
I guess these are because incompatibility between different versions of sdk . How can I resolve the same ?
Firstly,
setForeground(...)has been deprecated, and is no longer usable. See this blog for more details.You are getting this error because your minimum SDK level, defined in the manifest, is 3.
startForeground(...)requires API 5+.Now, in order to solve this, you cannot support anything below API 5; according to Dashboards, 99.3% of users have migrated to APIs 5+. To do this, set your
minSdkVersionto5, and remove your call tosetForeground(...). (This will solve both error messages.)Note:
setForeground(...)has since been removed from the SDK, and should no longer be used, ever, at all.