[英]creating on app for different Android version - available on lower versions with imports only in higher version
I know this kind of question has been asked before, for example here: Android: how to code depending on the version of the API? 我知道以前曾问过这种问题,例如在这里: Android:如何根据API版本进行编码?
There it is also mentioned that one has to compile to the newest Android level. 还提到了必须将其编译到最新的Android级别。 My basic app version should be available with 7 and the more advanced starting with level 12.
我的基本应用程序版本应从7开始提供,而更高级的版本应从12级开始。
So does that mean that the target setting of the project should be 12 as well as the min-sdk in the manifest. 这是否意味着项目的目标设置应该与清单中的min-sdk一样为12。
BUT the app in the Android market will then ONLY be available to level 12 devices? 但是,只有12级设备可以使用Android市场中的应用吗? Even though the app should run starting with 7 - just with limited features.
即使该应用程序应从7开始运行-功能也有限。
Also in level 12 I would need to import certain packages only available starting at 12. So I could not even set a lower Android target, otherwise I get compiler error. 同样在12级中,我将需要导入仅从12开始可用的某些软件包。因此,我什至无法设置较低的Android目标,否则会出现编译器错误。
So in summary: 因此,总而言之:
Many thanks! 非常感谢!
If I'm reading your question correctly then this would allow you application to be installed on devices with level 7 如果我正确阅读了您的问题,则可以将应用程序安装在7级级别的设备上
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="12" />
For development you can set it to any target you want ie your project target can be SDK 4.0 but you manifest target can be 1.5 (android:targetSdkVersion="3") or vice versa. 对于开发,您可以将其设置为所需的任何目标,即项目目标可以是SDK 4.0,但清单目标可以是1.5(android:targetSdkVersion =“ 3”),反之亦然。 Eclipse will give you a warning but you can develop for any target and set you manifest to any target as long as you take in to account the consequences.
Eclipse会警告您,但是您可以针对任何目标进行开发,并且只要考虑到后果,就可以将清单设置为任何目标。
You are probably aware there is a bit of work to do in you code to make sure the application doesn't crash if it tries to call methods that don't exist at level 7. I have written code to handle that if you want some examples. 您可能已经知道代码中需要做一些工作,以确保应用程序在尝试调用7级不存在的方法时不会崩溃。如果您需要一些代码,我已经编写了代码来处理例子。
EDIT: 编辑:
An example that works for me. 一个对我有用的例子。
/**
* Get the current SDK version as an integer. If we are using 1.5 the SDK is
* returned as a String so using the Build.VERSION.SDK_INT method will cause
* the application to crash. This method will return 3 if the version is 1.5
* and will return the proper result for Build.VERSION.SDK_INT if that
* method is available.
*
* @return
*/
public static int getSdkInt() {
if (Build.VERSION.RELEASE.startsWith("1.5"))
return 3;
try {
return YourInternalClass.getSdkIntInternal();
} catch (VerifyError e) {
Log.e(TAG, e.toString());
return 3;
}
}
You should call any methods that may not exist in an internal class so it wont load up until the method is called. 您应该调用内部类中可能不存在的任何方法,这样在调用该方法之前,它不会加载。
private static class YourInternalClass {
private static int getSdkIntInternal() {
return Build.VERSION.SDK_INT;
}
}
Now you can check the SDK version. 现在,您可以检查SDK版本。 If you have any methods that exist only in packages greater than 7, put those methods in an internal class.
如果有任何方法仅存在于大于7的程序包中,请将这些方法放在内部类中。 then you can do
那你就可以
if(TheClassYouPutThisMethodIn.getSDKInt() >= 12)
YourInternalClass.yourLevel12Method();
I'm sure there is probably a better way to do this (and I hope someone could post it) but it works great for me. 我确信可能有更好的方法可以做到这一点(我希望有人可以发布它),但对我来说很好。 I have applications that use methods from SDK 13 running safely on phone with level 3.
我的应用程序使用SDK 13中的方法在3级手机上安全运行。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.