11

I spent several hours by searching correct Intent for launching Data usage Activity in Android Settings. Unfortunetly i found nothing (on web and also here).

I also tried reflection (in a case of private field) but also without result. I will be glad for any help.

Thanks in advance.

Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106

3 Answers3

18

Try...

Intent intent = new Intent();
intent.setComponent(new ComponentName(
            "com.android.settings",
            "com.android.settings.Settings$DataUsageSummaryActivity"));
startActivity(intent);

This worked for me. I found it from the link to data usage in the KitKat QuickSettings source code.

imknown
  • 68
  • 1
  • 11
gsysko
  • 988
  • 1
  • 8
  • 19
  • There is no guarantee that this will work across devices and Android versions. – CommonsWare Oct 03 '14 at 21:32
  • @CommonsWare and what is? Is there an elegant way to find out if the above works on a specific device? – John Smith Oct 03 '14 at 22:24
  • @JohnSmith: "and what is?" -- there is no `Intent` action to drive to this screen. "Is there an elegant way to find out if the above works on a specific device?" -- well, that depends upon your definition of "works". You can see if the `Intent` will resolve via `PackageManager` and `resolveActivity()`, or just catching the `ActivityNotFoundException`. However, it's not out of the question that the `Intent` will resolve, but then the manufacturer simply craps out on the Settings side. *Probably* that won't happen. – CommonsWare Oct 03 '14 at 22:32
  • Thanks. I have resolved this by catching the exception and then move on to the next best one available, ACTION_SETTINGS. – John Smith Oct 05 '14 at 07:21
  • @JohnSmith is it pretty much guaranteed that this will at least work on devices >= 4.0? – boltup_im_coding Apr 17 '15 at 18:19
0

If you take a look at Android Settings manifest file and find activity section named "Settings$DataUsageSummaryActivity", it doesn't seem like it has an intent for being launched. Its intent filter has only one action tag(MAIN).

In Settings/AndroidManifest.xml,

<activity android:name="Settings$DataUsageSummaryActivity"
...>
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="com.android.settings.SHORTCUT" />
    </intent-filter>
...
</activity>

As you can see in this code, there is no custom action intent defined here.

sam
  • 2,780
  • 1
  • 17
  • 30
  • Can you add some snippet of code? Now im little confused from your reply. – Simon Dorociak Sep 26 '13 at 09:00
  • I don't think that's possible since it does not provide any extra action intent. Maybe you can start activity with its class name, but I am not sure if that is allowed. For your information, you might check settings constants here: http://developer.android.com/reference/android/provider/Settings.html – sam Sep 27 '13 at 13:25
  • I cannot find data usage summary settings from those constants but at least you can start a settings activity which is close to data usage summary. I hope this helps. – sam Sep 27 '13 at 13:27
-1

Take a look at Android Intents. They are talking about a ACTION_MANAGE_NETWORK_USAGE Intent.

Kyu_
  • 800
  • 4
  • 10
  • 18
  • Sorry but this won't launch data usage intent in Settings but thanks for answer. – Simon Dorociak Sep 26 '13 at 08:36
  • This will launch a prompt for the intent, with various resulting app resolvers, such as Exchange Services, Maps, Gmail, Youtube... None of them are the system preferences the OP asks for. gsysko's answer seems to work, but maybe not consistently across different manufacturers as pointed out by CommonsWare – leRobot May 25 '15 at 17:58