微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Wifi状态不会在android中改变?

如何解决Wifi状态不会在android中改变?

嗨,大家都在使用 android Q 设备,我有一个小问题,那就是 wifi 状态不会改变 这是我的代码

   

     public class wise extends AppCompatActivity {
    ActivityMainBinding binding;
  private WifiManager wifimanager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding=ActivityMainBinding.inflate(getLayoutInflater());
        View view=binding.getRoot();
        setContentView(view);
    wifimanager = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    binding.Switchbtn.setonCheckedchangelistener(new CompoundButton.OnCheckedchangelistener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
            if(isChecked){
                wifimanager.setWifiEnabled(true);
                binding.Switchbtn.setText("wifi is on ");
            }else {
                wifimanager.setWifiEnabled(false);
                binding.Switchbtn.setText("wifi is off ");
            }
            Toast.makeText(getApplicationContext(),String.valueOf(wifimanager.isWifiEnabled()),Toast.LENGTH_SHORT).show();
        }
    });
     if(wifimanager.isWifiEnabled()){
         binding.Switchbtn.setChecked(true);
         binding.Switchbtn.setText("wifi_is on");
     }else{

         binding.Switchbtn.setChecked(false);
         binding.Switchbtn.setText("wifi_is off");
     }
}}

这是我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.hello_world">

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <application

        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication">
        <activity android:name="com.example.hello_world.wise">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我用来自youtube的流程编写代码 是否有任何syggestions请帮忙 stackoverflow 询问更多帖子的详细信息,我没有,因为这是一个简单的问题,不需要太多细节,所以我写这个来填补帖子抱歉

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。