当前位置: 首页 > news >正文

Android10开机向导中复用设置中的Wifi界面

很多时候我们需要定制开机向导,在开机向导界面我们一般会实现联网和设置时间等功能,考虑复用与稳定性问题,我们最好复用设置中的WiFi设置和日期设置。但是设置中的wifi设置界面默认是没有下一步按钮的,这会让用户感觉很奇怪。

在以前7.0的代码中设置中有WifiSetupActivity 可让我们方便的集成,但在Android10上我们却找不到了。

    <activity android:name=".wifi.WifiSetupActivity"
282                 android:taskAffinity="com.android.wizard"
283                 android:theme="@style/SetupWizardDisableAppStartingTheme"
284                 android:label="@string/wifi_setup_wizard_title"
285                 android:icon="@drawable/empty_icon"
286                 android:clearTaskOnLaunch="true"
287                 android:windowSoftInputMode="adjustNothing">
288             <intent-filter android:priority="1">
289                 <action android:name="com.android.net.wifi.SETUP_WIFI_NETWORK" />
290                 <category android:name="android.intent.category.DEFAULT" />
291             </intent-filter>
292             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
293                 android:value="true" />
294         </activity>

那么Android原生的开机向导是如何处理的呢?

Android原生的开机向导是在packages/apps/Provision目录下,里面啥都没干,仅是设置了两个标志位后disable自身应用就finish掉了,用户感知不到。

    private void setProvision() {// Add a persistent setting to allow other apps to know the device has been provisioned.Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);// remove this activity from the package manager.PackageManager pm = getPackageManager();ComponentName name = new ComponentName(this, DefaultActivity.class);pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP);// terminate the activity.finish();}

可用命令读写相关标志位状态:

adb shell settings put global device_provisioned 1
adb shell settings put secure  user_setup_complete 1adb shell settings get  secure user_setup_complete
adb shell "settings get global device_provisioned"

其实原生设置界面中还是给我们留有接口,只是方式不一样。

在WifiSettings中搜索Setup,进一步我们可以发现如下一段代码:

        mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);if (mEnableNextOnConnection) {if (hasNextButton()) {final ConnectivityManager connectivity = (ConnectivityManager)getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);if (connectivity != null) {NetworkInfo info = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);changeNextButtonState(info.isConnected());}}}

这里说明了wifi界面最下面的”上一步和下一步“按钮是如何控制的。

另外在SettingsActivity.java中会通过启动时传的EXTRA_PREFS_SHOW_BUTTON_BAR 控制的。

// see if we should show Back/Next buttonsif (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {View buttonBar = findViewById(R.id.button_bar);if (buttonBar != null) {buttonBar.setVisibility(View.VISIBLE);Button backButton = findViewById(R.id.back_button);backButton.setOnClickListener(v -> {setResult(RESULT_CANCELED, null);finish();});Button skipButton = findViewById(R.id.skip_button);skipButton.setOnClickListener(v -> {setResult(RESULT_OK, null);finish();});mNextButton = findViewById(R.id.next_button);mNextButton.setOnClickListener(v -> {setResult(RESULT_OK, null);finish();});

所以我们在复用wifiSettings界面时,可用如下方法

 Intent i = new Intent(Settings.ACTION_WIFI_SETTINGS);i.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, true);i.putExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, true);startActivityForResult(i, REQUEST_CODE_WIFI);

日期设置界面同理,不过不需要传EXTRA_ENABLE_NEXT_ON_CONNECT。

如果我们需要对返回的结果做相关处理,可以复写onActivityResult,在这里做相关操作。

这样在开机向导中WiFi设置界面最下面就可以显示出上一步和下一步两个按钮了,如果嫌原生界面不好看,就只能自行修改settings了。

另外调试过程中 adb shell pm clear packageName 可快速清除开机向导保存的数据,加快调试速度。

Nice。

http://www.lryc.cn/news/37365.html

相关文章:

  • 川农机械专业小伙转行Java开发,年薪20w
  • 华为OD机试题 - 打印文件(JavaScript)| 机考必刷
  • 免费常用API大全,程序员必备
  • MySQL主从复制,读写分离
  • 什么是UEFI签名认证?UEFI签名有什么好处?
  • 案例14-课程推送页面逻辑整理--vue
  • 5大GPU厂商共建 | openKylin社区GPU SIG首次例会召开!
  • SpringBoot读取配置文件
  • 51驱动NRF24L01通信,NRF24L01与TTL转NRF24L01模块通信
  • C++友元
  • MySQL内置函数
  • mysql数据库之innodb存储引擎架构之内存架构
  • Vue:(三十五)路由vue-router
  • Dynabook笔记本电脑无法开机怎么重装新系统?
  • React Native基础知识点
  • nginx 平滑升级
  • 数据结构——链表OJ题目讲解(2)
  • GitHub上线重量级分布式事务笔记,再也不怕面试官问分布式了
  • C++语法规则1(C++面向对象 )
  • Web漏洞-CSRF漏洞
  • Python3-面向对象
  • 拐点!新能源车交付均价首次「低于」燃油车,智能电动成新爆点
  • JavaScript String 字符串对象实例合集
  • 实习生培养计划
  • 【服务器管理】Wordpress服务器内存占用太高(优化方案详解)
  • 【ECCV 2022】76小时动捕,最大规模数字人多模态数据集开源
  • 联合解决方案 | 亚信科技AntDB数据库携手浪潮K1 Power赋能关键行业数字化转型,助力新基建
  • Android 单元测试问题总结(Robolectric+JUnit)
  • 专项攻克——二叉树
  • PACS系统源码 PACS源码 三维重建PACS源码