android - 重定向用户以打开互联网设置

标签 android android-intent android-5.0-lollipop

我正在创建的应用程序需要互联网连接。我能够检查互联网是否可用并在 android 4.2.2 中以编程方式打开互联网。但我无法在 Lollipop 中自动打开。我搜索了一下,发现手机需要root才能使用setMobileDataEnabledgetMobileDataEnabled

如何将用户重定向到互联网设置,以便他/她可以打开它。打开它后,我如何自动将用户重定向回我的应用。

我根据 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/

相关文章:

android - 单击后退按钮后重定向到主页

java - Android 天气应用程序崩溃-网络错误

java - HandlerThread 的线程 ID - android

c# - 隐藏用于 editText 焦点/触摸的软键盘

android - 如何处理intet ://links in Android webview

android - 清除 Android 5+ 目录树选择器 (ACTION_OPEN_DOCUMENT_TREE) 中的历史记录(最近的文件夹)

android - 在 Android L 下使用 KeyGuardManager 时应用程序崩溃

android - 无尽的视频录制

android 在应用程序购买订阅购买 token 返回空值

android - 错误 : cannot find symbol variable LOLLIPOP