2013-11-27 35 views
0

我有一个问题:Android如何管理版本

我想为Android 3.0制作应用程序。 在我的应用我使用的通知是这样的:

android.app.Notification.Builder noti = new 
android.app.Notification.Builder(MyService.this) 
.setOngoing(true) 
.setContentTitle(getString(R.string.compose)) 
.setContentText(getString(R.string.details)) 
.setSmallIcon(icon) 
//.setPriority(NotificationCompat.PRIORITY_MIN) 
.setAutoCancel(false) 
.setWhen(0L) 
.setContentIntent(pIntentPost);  
Notification notif = noti.build(); 
mNotificationManager.notify(1337, notif); 

但我有一个PB,因为“noti.build”没有找到!

我已经试过这样:

NotificationCompat.Builder builder = new NotificationCompat.Builder(
MyService.this); 
Notification notification = builder.setContentIntent(pIntentPost) 
.setSmallIcon(icon).setOngoing(true) 
.setTicker(getString(R.string.compose)) 
.setWhen(0L) 
.setAutoCancel(false).setContentTitle(getString(R.string.compose)) 
.setContentText(getString(R.string.details)) 
.setPriority(NotificationCompat.PRIORITY_MIN).build(); 

但它不工作。

如何在我的应用程序中管理不同版本的Android?我必须导入特定的库?我不明白...

感谢您的帮助!

回答

2

只要你使用最新的SDK版本构建,您可以使用以下为例:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 
    // do Notification.Builder code for devices running 3.0 API or greater 
} else { 
    // do other code for devices running < 3.0 API 
} 
+0

确定,但我如何删除errrors在我的有关代码noti.build();和.setPriority(NotificationCompat.PRIORITY_MIN)我有这些配置:目标API目标= android-11和有什么问题? – user2402911

+0

您使用哪个SDK版本进行编译?如果您使用包含这些方法的SDK版本,只要您使用我提到的代码保护它,lint错误就会消失。否则,如果由于某种原因lint仍然存在问题,那么有一种方法可以配置Eclipse(假设您使用的是Eclipse),它仍然允许它以这种方式进行编译。 – anddev84

+0

我在Target API target = android-11并将它放在Target API target = android-17它编译thxs!我希望一切都好! – user2402911