如果设备支持 SDK <= 13,我只想显示 Toast
我正在编写一个小程序,如果目标 sdk 大于或等于 14,则允许用户向用户添加事件,否则显示 Toast,但不幸的是,每当我在支持 API 级别 8 或 < 14 代替 Toast,见下面的代码:
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
if(Build.VERSION.SDK_INT > 8 && Build.VERSION.SDK_INT < 13)
{
Toast.makeText(getApplicationContext(), "Some Message", Toast.LENGTH_LONG).show();
}
else
{
Intent calIntent = new Intent(Intent.ACTION_INSERT);
calIntent.setData(Events.CONTENT_URI);
calIntent.putExtra(Events.TITLE, title.toString());
calIntent.putExtra(Events.EVENT_LOCATION, KEY_LOCATION);
calIntent.putExtra(Events.DESCRIPTION, description.toString());
startActivity(calIntent);
}
}
});
}
日志猫:
10-30 12:24:27.142: E/AndroidRuntime(330): FATAL EXCEPTION: main
10-30 12:24:27.142: E/AndroidRuntime(330): java.lang.NoClassDefFoundError: android.provider.CalendarContract$Events
10-30 12:24:27.142: E/AndroidRuntime(330): at com.example.multileveljson.ProductDetailActivity$1.onClick(ProductDetailActivity.java:51)
10-30 12:24:27.142: E/AndroidRuntime(330): at android.view.View.performClick(View.java:2408)
10-30 12:24:27.142: E/AndroidRuntime(330): at android.view.View$PerformClick.run(View.java:8816)
10-30 12:24:27.142: E/AndroidRuntime(330): at android.os.Handler.handleCallback(Handler.java:587)
10-30 12:24:27.142: E/AndroidRuntime(330): at android.os.Handler.dispatchMessage(Handler.java:92)
10-30 12:24:27.142: E/AndroidRuntime(330): at android.os.Looper.loop(Looper.java:123)
10-30 12:24:27.142: E/AndroidRuntime(330): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-30 12:24:27.142: E/AndroidRuntime(330): at java.lang.reflect.Method.invokeNative(Native Method)
10-30 12:24:27.142: E/AndroidRuntime(330): at java.lang.reflect.Method.invoke(Method.java:521)
10-30 12:24:27.142: E/AndroidRuntime(330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-30 12:24:27.142: E/AndroidRuntime(330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-30 12:24:27.142: E/AndroidRuntime(330): at dalvik.system.NativeStart.main(Native Method)
我能够向使用目标 SDK >= 14 的设备添加事件,但无法在使用目标 SDK <= 13 的设备上显示 Toast ....