在开发Android应用程序时,Min和Target SDK版本有什么区别?除非Min和Target版本相同,否则Eclipse不会让我创建一个新项目!
在Android中我很容易得到SDK的版本(Build.VERSION.SDK)但是只有当平台比1.6(>Build.VERSION_CODES.DONUT)更新时我才需要使用LabeledIntent
我认为反思是必要的(我已经阅读过这个链接,但对于一个班级或我来说,这是不明确的).
这是代码,但它给了我一个例外,因为在我的Android 1.6中,编译器会验证包是否存在,即使条件未应用:
Intent theIntent=....;
if(Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.DONUT)
{
try{
Intent intentChooser = Intent.createChooser(intent,"Choose between these programs");
Parcelable[] parcelable = new Parcelable[1];
parcelable[0] = new android.content.pm.LabeledIntent(theIntent, "", "Texto plano", 0);
intentChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, parcelable);
activity.startActivity(intentChooser);
}
catch(Exception e)
{
activity.startActivity(theIntent);
}
} else
{
activity.startActivity(intentMedicamento);
}
Run Code Online (Sandbox Code Playgroud)
我如何解决它,一些注意到正确的答案
@Commonsware告诉我如何做到这一点.我们创建一个桥类,以便根据API LEVEL实例化一个使用API LEVEL的类或另一个使用另一个API LEVEL的类.一个初学者可以忘记的唯一细节是你必须使用最新的SDK编译你的应用程序,你可以参考.
public abstract class LabeledIntentBridge {
public abstract Intent BuildLabeledIntent(String URL, Intent theintent);
public static final LabeledIntentBridge INSTANCE=buildBridge();
private static LabeledIntentBridge buildBridge() {
int sdk=new …Run Code Online (Sandbox Code Playgroud)