且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用ACTION_CAPTIVE_PORTAL_SIGN_IN

更新时间:2023-12-04 16:13:52

它可用于允许您的应用执行强制门户Wi-Fi登录.假设清单中包含以下内容:

It can be used to allow your app to perform captive portal Wi-Fi sign in. Assuming you have something like this in your manifest:

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

这是可能发生的事情:

  1. 设备连接到专属Wi-Fi门户
  2. 系统显示强制性门户通知
  3. 用户触摸通知
  4. 系统显示隐式意图应用选择器
  5. 用户选择SignInActivity
  6. SignInActivity已启动
  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. SignInActivity is launched

您可以访问 ConnectionManager.ACTION_CAPTIVE_PORTAL_SIGN_IN 中提到的其他功能>使用 getIntent() ConnectivityManager.EXTRA_NETWORK (类型为 Network )与门户网站( ie )通信通过登录令牌),以及 ConnectivityManager.EXTRA_CAPTIVE_PORTAL 额外的(类型为 CaptivePortal )以与系统就结果进行通信登录的位置.

You may access the extras mentioned in the ConnectionManager.ACTION_CAPTIVE_PORTAL_SIGN_IN using getIntent() and getParcelableExtra(). Use the ConnectivityManager.EXTRA_NETWORK extra (which has type Network) to communicate with the portal (i.e. pass sign in tokens), and the ConnectivityManager.EXTRA_CAPTIVE_PORTAL extra (which has type CaptivePortal) to communicate with the system about the outcome of the sign in.