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

Abh*_*bhi 2 android android-intent android-5.0-lollipop

我正在创建的应用程序需要互联网连接.我能够检查互联网是否在Android 4.2.2中以编程方式启用互联网.但是我无法在棒棒糖中自动开启.我搜索了一下,发现手机需要扎根才能使用setMobileDataEnabledgetMobileDataEnabled.

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

我根据SO帖子尝试了这个:

                Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName(MainActivity.this,
                    "com.android.phone.NetworkSetting");
            startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

但是我得到了这个错误 android.content.ActivityNotFoundException: Unable to find explicit activity class {com.prematixsofs.taxiapp/com.android.phone.NetworkSetting}; have you declared this activity in your AndroidManifest.xml?

Gav*_*iel 5

// either this:
    Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
// or this:
    Intent settingsIntent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);

    activity.startActivityForResult(settingsIntent, 9003);
Run Code Online (Sandbox Code Playgroud)