简体   繁体   中英

Send user to preferences on Android after button is clicked

I have an Android app which requires the user to be connected to the Internet. If the user is not online, the app shows an AlertDialog which says: "You have to be connected to the Internet to use this app". In that AlertDialog I have a button. Can I some how send the user to preferences, so the user can turn internet on and return to my app? So when the user returns I just run my methods to get the information from the services I use.

Use this code:

    startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));

EDIT: you could use:

    startActivityForResult(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK), PICK_WIFI_REQUEST_CODE);

and then override:

   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
       //Check if you have internet
       //... proceed to next Activity
   }

Create a new Intent using the current class activity and the WifiManager constant to search for network/pick a network. Start the activity and wait for result.

Intent intent = new Intent(activity.this, WifiManager.ACTION_PICK_WIFI_NETWORK);
startActivityForResult(intent,1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM