位置: 编程技术 - 正文

Android 4.1.2为通知栏添加wifi开关(安卓hid通信)

编辑:rootadmin
摘自: 4.1.2系统中,默认的通知栏上有个WIFI的选项,点击该选项系统会弹出settings应用的wifi设置页面,而后我们进行wifi的连接,并且可以正常上网。理论上在之后的使用中我们可以一直打开着wifi,而不用再次进入wifi设置页面,但偶尔还是需要关闭wifi,比如为了省电。此时当我们要关闭的时候,还是需要进入wifi设置页面。所以为了方便期间,可以通过修改SystemUI的通知栏,zaiwifi一栏添加一个wifi的开关,这样就可以很方便的打开和关闭wifi了。为实现此功能,我们需要修改两个地方,首先需要在frameworks/base/packages/SystemUI/res/layout/system_bar_settings_view.xml中添加wifi栏上的开关按钮:<!-- Network --> <LinearLayout android:id="@&#;id/network" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@&#;id/network_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/ic_sysbar_wifi_on" /> <TextView android:id="@&#;id/network_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_wifi_butt /> <switch< span="" style="word-wrap: break-word;"> android:id="@&#;id/network_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp通过添加名为network_checkbox的开关按钮,就可以在wifi设置栏上显示一个开关了。接下来需要添加对此开关的操作代码,我们需要修改frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.javaimport android.content.BroadcastReceiver;import android.net.wifi.WifiManager;import android.content.IntentFilter;public class SettingsView extends LinearLayout implements View.OnClickListener { static final String TAG = "SettingsView"; AirplaneModeController mAirplane; AutoRotateController mRotate; BrightnessController mBrightness; DoNotDisturbController mDoNotDisturb; View mRotationLockContainer; View mRotationLockSeparator; private CompoundButton mNetworkCheckbox; private BroadcastReceiver WifiStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); int wifiState = wifiManager.getWifiState(); if (wifiState == wifiManager.WIFI_STATE_ENABLED) mNetworkCheckbox.setChecked(true); else if (wifiState == wifiManager.WIFI_STATE_DISABLED) { mNetworkCheckbox.setChecked(false); } } } }; private CompoundButton.OnCheckedChangeListener NetworkCheckboxHandler = new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton view, boolean checked) { WifiManager wifiManager = (WifiManager)getContext().getSystemService(Context.WIFI_SERVICE); int wifiState = wifiManager.getWifiState(); if (checked) { if (wifiState == wifiManager.WIFI_STATE_DISABLED) { Slog.d(TAG, "WIFI enablen"); wifiManager.setWifiEnabled(true); } } else { if (wifiState == wifiManager.WIFI_STATE_ENABLED) { Slog.d(TAG, "WIFI disablen"); wifiManager.setWifiEnabled(false); } } } }; public SettingsView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public SettingsView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onFinishInflate() { super.onFinishInflate(); final Context context = getContext(); mAirplane = new AirplaneModeController(context, (CompoundButton)findViewById(R.id.airplane_checkbox)); findViewById(R.id.network).setOnClickListener(this); mNetworkCheckbox = (CompoundButton)findViewById(R.id.network_checkbox); mNetworkCheckbox.setOnCheckedChangeListener(NetworkCheckboxHandler); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); IntentFilter wifiIntentFilter = new IntentFilter(); wifiIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); context.registerReceiver(WifiStateReceiver, wifiIntentFilter); mRotationLockContainer = findViewById(R.id.rotate); mRotationLockSeparator = findViewById(R.id.rotate_separator); mRotate = new AutoRotateController(context, (CompoundButton)findViewById(R.id.rotate_checkbox), new AutoRotateController.RotationLockCallbacks() { @Override public void setRotationLockControlVisibility(boolean show) { mRotationLockContainer.setVisibility(show ? View.VISIBLE : View.GONE); mRotationLockSeparator.setVisibility(show ? View.VISIBLE : View.GONE); } }); mBrightness = new BrightnessController(context, (ToggleSlider)findViewById(R.id.brightness)); mDoNotDisturb = new DoNotDisturbController(context, (CompoundButton)findViewById(R.id.do_not_disturb_checkbox)); findViewById(R.id.settings).setOnClickListener(this); }这里说明一下,主要改动是在onFinishInflate函数中获取到开关控件network_checkbox,而后为其添加setOnCheckedChangeListener以处理用户的点击事件,在点击回调里,通过wifiManager.setWifiEnabled函数打开和关闭wifi。而注册一个WifiStateReceiver主要是用来同步wifi的开关状态的,因为如果用户在Settings里面打开了wifi,那相应的状态栏中的wifi开关状态也应该跟着同步变化。修改后效果如下:

推荐整理分享Android 4.1.2为通知栏添加wifi开关(安卓hid通信),希望有所帮助,仅作参考,欢迎阅读内容。

Android 4.1.2为通知栏添加wifi开关(安卓hid通信)

文章相关热门搜索词:安卓通用,安卓通道,android 通信,android系统提供了什么通信,android 通信,android 通信,android 通信,android通信协议,内容如对您有帮助,希望把文章链接给更多的朋友!

Android 4.4 eng版本 红框问题 在android4.4.2中编译的eng版本经常出现红框的问题。通过排查因为在frameworks/base/core/java/android/os/StrictMode.java文件中打开了设置选项具体修改如下:---a/frame

Activity与Fragment数据传递之Fragment从Activity获取数据 整理Fragment与Activity之间的数据交换,大体上包括三种:1、Fragment从Activity获取数据2、Activity从Fragment获取数据3、Fragment之间获取数据通常,如果Activity向

使用android.graphics.Path类自绘制PopupWindow背景 PopupWindow简介PopupWindow是悬浮在当前activity上的一个容器,用它可以展示任意的内容。PopupWindow跟位置有关的API有下面几个:showAsDropDown(Viewanchor,intxoff,intyo

标签: 安卓hid通信

本文链接地址:https://www.jiuchutong.com/biancheng/379577.html 转载请保留说明!

上一篇:Android ListViewitem滑动出现删除按钮

下一篇:Android 4.4 eng版本 红框问题(android4.4iso)

  • 小规模纳税人每月不超过10万
  • 汽车购置税怎么在手机上缴费
  • 即征即退收入要交税吗
  • 由商场代收营业费怎么算
  • 合并报表中怎么抵消投资性房地产
  • 商品的入账价值包括消费税吗
  • 银行贷款受托支付后,钱怎么转回来
  • 铸造厂的销售废料有哪些
  • 门诊药房主要业务
  • 外汇税收怎么缴纳增值税
  • 预支备用金填请款单还是借支单
  • 小规模个人所得税怎么申报
  • 主营业务收入冲销
  • 固定资产报废残料收入的账务处理
  • 如何异地缴纳个人医保
  • 自产自销的产品怎么做账
  • 劳务费需要预缴税款吗
  • 企业定期存款是什么账户类型
  • 企业支付宝可以转账到对公账户吗
  • 证券投资基金管理人的职权
  • 买一赠一商品必须一样吗
  • 租入办公设备的租金计入什么科目
  • 销售蔬菜免税账务处理
  • 灭火器属于办公设施吗
  • windows10如何清理c盘垃圾
  • win没有投影到此电脑怎么办
  • win7纯净版系统官网
  • 借用资质(挂靠施工)的法律责任如何判断?
  • win7系统修改
  • Pycharm安装库失败
  • 中小企业发展专项资金绩效评价报告
  • 油卡预付卡发票能入费用吗怎么入账
  • 使用的拼音
  • 基于stm32的飞行器
  • 前端脚本开发
  • logparser命令
  • 进项税额转出在申报的时候怎么填
  • 代扣代缴的企业所得税计入成本吗
  • django中httpresponse
  • 红字写信是什么意思
  • 研发费用加计扣除新税收政策
  • 应付账款转入营业外收入的证明
  • 为什么企业一定要上政企通
  • vue导航方式
  • 个税申报表中的年金是什么意思?
  • 领备用金填什么单子
  • 物业合并利润表怎么填
  • SQL server 2008中的数据库能否只包含数据文件
  • 分公司计提递延所得税吗
  • 代扣缴纳税款会计分录
  • 技术报酬金是什么意思
  • 工会应付下级经费
  • 旅行社差额征税全额开票和差额开票
  • 现金流量表是年度报表
  • 政府会计工资代扣工会会费
  • 事业单位利息收入
  • 一般纳税人主表中的25是怎么来的
  • 毛利润利润总额净利润的关系图
  • 固定资产的特点有哪几个
  • 百旺金赋税盘怎么清卡
  • 年末进项大于销项怎么结转
  • 销项负数发票如何作废
  • 销售费用包括哪些内容?其明细科目有哪些?
  • win8系统蓝屏后无法修复
  • windows隐藏
  • macu盘安装windows
  • won10安装
  • linux安装glibc.i686
  • 邮箱应用程序
  • w8虚拟内存怎么设置
  • perl localtime函数
  • 使用vue-cli快速搭建vue项目
  • 噩梦act2
  • python程序员必读书籍
  • unity behavior designer
  • jquery有哪些
  • python遍历文件
  • 审计局查什么内容
  • 怎么查询工程师名下的项目
  • 邮政银行开税票要什么材料
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设