Which intent should open Data Usage screen (from settings)

♀尐吖头ヾ 提交于 2019-12-08 16:55:26

问题


I wish to open the Data Usage screen from an intent. I've searched the android.provider.Settings class for an appropriate intent. Tried :

new Intent(android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS)
new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS)

Which doesn't lead to the the data usage.

I'm well aware of all the links which has this question, but none has a response. How to open System Data Usage Activity in android? Android programming to open Data Usage setting page etc...


回答1:


You can use this to achieve the above !! I tested this on Kitkat and lollipop devices , On both of them its working

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



回答2:


private static final String SETTINGS_PACKAGE = "com.android.settings";
private static final String SETTINGS_CLASS_DATA_USAGE_SETTINGS = "com.android.settings.Settings$DataUsageSummaryActivity";

try {
            final Intent intent = new Intent(Intent.ACTION_MAIN, null);
            final ComponentName cn = new ComponentName(SETTINGS_PACKAGE, SETTINGS_CLASS_DATA_USAGE_SETTINGS);
            intent.setComponent(cn);
            context.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Log.v(TAG, "Data settings usage Activity is not present");
        }


来源:https://stackoverflow.com/questions/31700842/which-intent-should-open-data-usage-screen-from-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!