我正在创建的应用程序需要互联网连接。我能够检查互联网是否可用并在 android 4.2.2 中以编程方式打开互联网。但我无法在 Lollipop 中自动打开。我搜索了一下,发现手机需要root才能使用setMobileDataEnabled
和getMobileDataEnabled
。
如何将用户重定向到互联网设置,以便他/她可以打开它。打开它后,我如何自动将用户重定向回我的应用。
我根据 SO 帖子尝试了这个:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(MainActivity.this,
"com.android.phone.NetworkSetting");
startActivity(intent);
但是我得到这个错误
android.content.ActivityNotFoundException:无法找到明确的 Activity 类 {com.prematixsofs.taxiapp/com.android.phone.NetworkSetting};您是否已在 AndroidManifest.xml 中声明此 Activity ?
最佳答案
// either this:
Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
// or this:
Intent settingsIntent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
activity.startActivityForResult(settingsIntent, 9003);
关于android - 重定向用户以打开互联网设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34893650/