8

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

Programmer Bruce
  • 64,977
  • 7
  • 99
  • 97
dackyD
  • 267
  • 2
  • 4
  • 14

3 Answers3

17

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.

Amanda S
  • 3,266
  • 4
  • 33
  • 45
Naresh
  • 1,336
  • 9
  • 14
  • 3
    This is not working on Android 4.1 anymore, any idea how to do it there? – Michalsx Jul 01 '12 at 16:53
  • To make this work with Android 4.1, I removed the component... But I do not know why. – Rémi F Aug 29 '12 at 14:17
  • As CommonsWare notes below, this was a bug in Android =(#13368), which meant you must specify the component. I fixed this for Android 4.0, so the component is no longer required. As for Android 4.1, possibly the class name changed -- you cannot rely on these remaining constant across Android versions or device manufacturers. – Christopher Orr Oct 17 '12 at 10:05
  • @buzeeg hey can you please explain? did you mean like this http://stackoverflow.com/a/6789616 – Amel Jose Jun 18 '13 at 09:58
  • 1
    @AmelJose hi! I made it work like that : https://github.com/buzeeg/datasettings/blob/master/src/com/remifayolle/android/datasettings/DataSettingsActivity.java – Rémi F Jul 15 '13 at 19:21
4

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Was also interested why it does not work. Tried that without FLAG_ACTIVITY_NEW_TASK, using the same approach that normally works for other Settings screens. Definitely it crashes on Nexus One. Really strange. – Zelimir Dec 10 '10 at 14:28
  • @Desiderio: See my update above -- the Settings app does not seem to support this action. – CommonsWare Dec 10 '10 at 15:20
  • Thanks for clarification. Looked like something of that kind. – Zelimir Dec 10 '10 at 15:23
  • Thanks for all your answers. I tested this on both 1.5 HTC Magic and 2.2 HTC Desire device. How can we follow up this bug? Will you come back to this thread and give us updates? – dackyD Dec 12 '10 at 11:40
  • @dackyD: No sign of it being honored in Android 2.3 either, so I have opened an issue on it: http://code.google.com/p/android/issues/detail?id=13368 – CommonsWare Dec 22 '10 at 13:50
1

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

Mario
  • 405
  • 7
  • 15