为什么没有sdk版本检查工作?

时间:2016-01-31 18:00:32

标签: android sdk android-api-levels

我有这段代码:

int currentapiVersion = android.os.Build.VERSION.SDK_INT;

            if (currentapiVersion < Build.VERSION_CODES.JELLY_BEAN) {
                Intent intent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);
                ComponentName cName = new ComponentName("com.android.phone", "com.android.phone.Settings");
                intent.setComponent(cName);

            } else {
                Intent intent = new Intent();
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setAction(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS);
                context.startActivity(intent);
            }

为什么我的Android手机(api等级15)没有这个功能,但当我用下面的代码替换它时,它运行正常?

                Intent intent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);
                ComponentName cName = new ComponentName("com.android.phone", "com.android.phone.Settings");
                intent.setComponent(cName);

2 个答案:

答案 0 :(得分:0)

  

if(currentapiVersion&lt; Build.VERSION_CODES.JELLY_BEAN){

            Intent intent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);

            ComponentName cName = new ComponentName("com.android.phone", "com.android.phone.Settings");

            intent.setComponent(cName); 

            context.startActivity(intent);


        } else {

            Intent intent = new Intent();

            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

         intent.setAction(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS);
            context.startActivity(intent);
        }

答案 1 :(得分:0)

你没有调用startActivity,如果Block出现问题的原因

相关问题