Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

android - Launching mobile network settings screen programmatically

I want to launch mobile network settings screen, so that user can enable/disable 3g or data connection. Can anybody tell me which intent I need to use for starting activity. I used

Intent in = new Intent(android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS ) 

and

Intent in = new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS  ). 

but both of these didn't work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

They won't work because there was a bug that was fixed I think in 2.3.

See https://review.source.android.com/#/c/22229/

You can bypass this using (for NETWORK_OPERATOR_SETTINGS)

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.phone", "com.android.phone.NetworkSetting");
startActivity(intent);

Replace NetworkSetting with Settings for DATA_ROAMING_SETTINGS

there's another similar solution described in Error opening mobile network settings menu

UPDATE

I recently tested this and it seems that this workaround is still necessary up to API level 15. Since API level 16 the intents in the question seem to work correctly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...