Which Intent for Settings - Data usage

2019-01-15 08:03发布

问题:

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.

回答1:

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.



回答2:

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.



回答3:

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