-2

我有这个代码片段:

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 level 15) 上不起作用,但是当我用下面的代码替换它时,它工作正常?

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

2 回答 2

0

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); 

            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);
        }
于 2016-01-31T18:12:24.150 回答
0

你没有在 if Block 中调用 startActivity 这就是问题发生的原因

于 2016-01-31T18:13:34.483 回答