提交 e89215ef authored 作者: 刘建胜's avatar 刘建胜

[Feat] 添加检查WIFI休眠策略

上级 efdcc4d1
......@@ -8,7 +8,7 @@ android {
defaultConfig {
applicationId "com.ubains.demorx356x"
minSdk 25
targetSdk 32
targetSdk 28
versionCode 1
versionName "1.0"
......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.ubains.demorx356x">
package="com.ubains.demorx356x"
android:sharedUserId="android.uid.system">
<uses-permission android:name="android.permission.INTERNET"/>
......
......@@ -2,11 +2,18 @@ package com.ubains.demorx356x;
import androidx.appcompat.app.AppCompatActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.yx.IYxInstallListener;
import android.os.yx.YxDeviceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
......@@ -22,6 +29,7 @@ import java.util.Calendar;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
final YxDeviceManager yxDeviceManager = YxDeviceManager.getInstance(this);
TextView tvLog;
......@@ -63,6 +71,19 @@ public class MainActivity extends AppCompatActivity {
YxDeviceManager.getInstance(getApplication()).setOemFunc("io50");
}
});
//注册广播监听WIFI状态变化
registerWifiReceiver();
}
private void registerWifiReceiver() {
// 创建Wifi状态变化的IntentFilter
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
// 注册BroadcastReceiver
registerReceiver(wifiStateReceiver, intentFilter);
}
/**
......@@ -91,6 +112,16 @@ public class MainActivity extends AppCompatActivity {
info.append("屏幕方向:").append(yxDeviceManager.getScreenRotation()).append("\n");
info.append("序列号:").append(yxDeviceManager.getSerialno()).append("\n");
info.append("内部存储大小:").append(yxDeviceManager.getInternalStorageMemory()).append("\n");
//读取WIFI的默认策略
int wifiSleepPolicy = Settings.System.getInt(getContentResolver(),
android.provider.Settings.System.WIFI_SLEEP_POLICY,
Settings.System.WIFI_SLEEP_POLICY_DEFAULT);
System.out.println("---> 修改前的Wifi休眠策略值 WIFI_SLEEP_POLICY=" + wifiSleepPolicy);
info.append("WIFI_SLEEP_POLICY:").append(wifiSleepPolicy).append("\n");
tvLog.setText(info.toString());
}
......@@ -171,7 +202,7 @@ public class MainActivity extends AppCompatActivity {
public void sliceInstall(View view) {
File apkFile = new File("/sdcard/update.apk");
if(!apkFile.exists()){
if (!apkFile.exists()) {
tvLog.setText("/sdcard/update.apk 文件不存在");
return;
}
......@@ -181,4 +212,36 @@ public class MainActivity extends AppCompatActivity {
public void sliceUninstall(View view) {
yxDeviceManager.unInstallApk("org.videolan.vlc");
}
public void turnOffScreen(View view) {
yxDeviceManager.setScreenKeyGuard(false);
}
public void setWifiSleepPolicyNever(View view) {
Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.WIFI_SLEEP_POLICY,
Settings.System.WIFI_SLEEP_POLICY_NEVER);
tvLog.setText("OK!");
}
private final BroadcastReceiver wifiStateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
switch (wifiState) {
case WifiManager.WIFI_STATE_ENABLED:
Log.d(TAG, "onReceive: Wifi已启用");
break;
case WifiManager.WIFI_STATE_DISABLED:
Log.d(TAG, "onReceive: Wifi已禁用");
break;
case WifiManager.WIFI_STATE_UNKNOWN:
Log.d(TAG, "onReceive: Wifi状态未知");
break;
}
}
};
}
\ No newline at end of file
......@@ -113,6 +113,18 @@
android:onClick="closeStatusBar"
android:text="隐藏状态栏"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="setWifiSleepPolicyNever"
android:text="设置WIFI息屏不休眠"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="turnOffScreen"
android:text="息屏"
/>
</LinearLayout>
</ScrollView>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论