我喜欢涵盖所有 API 级别的通知。要使用TaskStackBuilde
,我需要 API 级别最低 16。我不想设置minSdkVersion
为 16,因为我的应用程序的目标是较低的 API 级别。所以我如何编码是检测 API 级别,如果高于 16,我遵循这种格式。如果 Sdk 较低,我遵循该格式。我想成为以下
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN){
// Do something for JELLY_BEAN and above versions
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(DetailMapView.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
} else{
// do something for phones running an SDK before JELLY_BEAN
Intent intent = new Intent(context, DetailMapView.class);
PendingIntent activity = PendingIntent.getActivity(context, 0, intent, 0);
mBuilder.setContentIntent(activity);
}
但是代码有错误,TaskStackBuilde
因为我的 minSdk 是 8。我不想更改为 16,因为我想将我的应用程序用于较低的 API 级别。我该如何解决?任何可用的示例代码?谢谢