5

Can anyone suggest how to open captive portal inside android app?

i have gone through below links https://developer.android.com/reference/android/net/CaptivePortal.html Using ACTION_CAPTIVE_PORTAL_SIGN_IN

Can anyone have a complete guide to use captive portal inside android application?

Pratik
  • 442
  • 4
  • 17

3 Answers3

5

Following is flow of pushing captive portals

enter image description here

Use following android doc for programming part

https://developer.android.com/reference/android/net/CaptivePortal.html

Think this will useful

Nisal Edu
  • 5,371
  • 3
  • 22
  • 31
4

WifiPortalAutoLog is an example project that you can use

As describe in this answer: Here is an example scenario:

  1. Device connects to captive Wi-Fi portal
  2. System displays a captive portal notification
  3. User touches the notification
  4. System displays the implicit intent app chooser
  5. User selects SignInActivity
  6. MainActivity is launched

In MainActivity You may access the extras mentioned in the ConnectionManager.ACTION_CAPTIVE_PORTAL_SIGN_IN :

if (ConnectivityManager.ACTION_CAPTIVE_PORTAL_SIGN_IN.equals(intent.getAction())) {

get captivePortal from bundle to communicate with the system about the outcome of the sign in:

captivePortal = intent.getParcelableExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL);

Use the ConnectivityManager.EXTRA_NETWORK extra (which has type Network) to communicate with the portal (i.e. pass sign in tokens):

net = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK);

Load url in WebView and also remember set intent filter in manifest:

<activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.net.conn.CAPTIVE_PORTAL" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
</activity>
Hamed Ghadirian
  • 5,491
  • 4
  • 40
  • 63
0

All android devices dont work the same for captive portal. You need to check as per your app requirements. Samsung uses the android captive portal mechanism by redirecting portal to their system, handles it internally and blocks other captive portal requests and shows on its own browser. Like Samsung, some other vendors like Huawei and more too use their own mechanism and only some including Oneplus, Mi, Htc and others use default mechanism and hence can be redirected to the app using the portal intent filter but not for else.

<intent-filter>
  <action android:name="android.net.conn.CAPTIVE_PORTAL"/>
  <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

One link explaining it clearly is here:

https://community.arubanetworks.com/t5/Wireless-Access/Samsung-Captive-Portal-Detection/m-p/405934#M78972