Error opening mobile network settings menu

2019-01-14 13:49发布

Hi I would like to open the mobile network settings with this code:


Intent intentSettings = new Intent();

intentSettings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentSettings.setAction(Settings.ACTION_DATA_ROAMING_SETTINGS);
             cont.startActivity(intentSettings);

but it gives me this error. Any ideas anyone?

12-10 11:17:34.902: ERROR/AndroidRuntime(623): android.content.ActivityNotFoundException: No Activity found to handle Intent { action=android.settings.DATA_ROAMING_SETTINGS flags=0x4000000 }

Thanks

3条回答
劫难
2楼-- · 2019-01-14 14:14

This works the same for the ACTION_NETWORK_OPERATOR_SETTINGS, just add the following component:

Intent intent=new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS);

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

intent.setComponent(cName);

查看更多
啃猪蹄的小仙女
3楼-- · 2019-01-14 14:20

To get this working, change your intent creation to the following code:

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

Basically the android manifest requires a component filter.

查看更多
祖国的老花朵
4楼-- · 2019-01-14 14:29

You could try getting rid of the FLAG_ACTIVITY_NEW_TASK, which may not be needed in this case, and see if that helps.

If that does not help, then either:

  • You are running this on Android 1.1 or earlier (seems unlikely)
  • You are running this on a device with a compatibility issue (if so, please let me know what device it is)
  • Something really strange is going on

UPDATE

It appears the answer is the third bullet above. While ACTION_DATA_ROAMING_SETTINGS is in the documentation, the Settings application itself does not have an <intent-filter> for it.

I will check back when the Android 2.3 source is released and see if that changes the story any. If not, I will file a bug, because either it is a documentation error or a Settings application error, IMHO.

查看更多
登录 后发表回答