version:2.1.2
bugfixes: update:显示联想应用市场,22点到7点不报时
This commit is contained in:
@@ -16,8 +16,8 @@ android {
|
|||||||
minSdkVersion 24
|
minSdkVersion 24
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
|
|
||||||
versionCode 208
|
versionCode 212
|
||||||
versionName "2.0.7"
|
versionName "2.1.2"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,9 @@
|
|||||||
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
|
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
|
||||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||||
<uses-permission android:name="android.permission.READ_SMS" />
|
<uses-permission android:name="android.permission.READ_SMS" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_SMS" /><!-- 接收短信权限 -->
|
<!-- 接收短信权限 -->
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||||
|
<uses-permission android:name="android.permission.BIND_JOB_SERVICE" />
|
||||||
|
|
||||||
<!-- 允许访问网络,必选权限 -->
|
<!-- 允许访问网络,必选权限 -->
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
@@ -161,8 +163,8 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".activity.contact.ContactListActivity"
|
android:name=".activity.contact.ContactListActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:theme="@style/AppTheme"
|
android:screenOrientation="portrait"
|
||||||
android:screenOrientation="portrait" />
|
android:theme="@style/AppTheme" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.dock.DockActivity"
|
android:name=".activity.dock.DockActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
@@ -196,8 +198,8 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".activity.emergency.EmergencyActivity"
|
android:name=".activity.emergency.EmergencyActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:theme="@style/AppBlackTheme"
|
android:screenOrientation="portrait"
|
||||||
android:screenOrientation="portrait" />
|
android:theme="@style/AppBlackTheme" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.noti.NoticeActivity"
|
android:name=".activity.noti.NoticeActivity"
|
||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
@@ -226,13 +228,13 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".activity.FlashlightActivity"
|
android:name=".activity.FlashlightActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:theme="@style/AppTheme"
|
android:screenOrientation="portrait"
|
||||||
android:screenOrientation="portrait" />
|
android:theme="@style/AppTheme" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.NetworkActivity"
|
android:name=".activity.NetworkActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:theme="@style/AppTheme"
|
android:screenOrientation="portrait"
|
||||||
android:screenOrientation="portrait" />
|
android:theme="@style/AppTheme" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.selectnumber.SelectNumberActivity"
|
android:name=".activity.selectnumber.SelectNumberActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
@@ -255,8 +257,8 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".activity.contact.AddContactActivity"
|
android:name=".activity.contact.AddContactActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:theme="@style/AppTheme"
|
android:screenOrientation="portrait"
|
||||||
android:screenOrientation="portrait" />
|
android:theme="@style/AppTheme" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.callwechat.CallWechatActivity"
|
android:name=".activity.callwechat.CallWechatActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
|
|||||||
@@ -648,7 +648,7 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
|
|||||||
// @Override
|
// @Override
|
||||||
// public void onChanged(Integer integer) {
|
// public void onChanged(Integer integer) {
|
||||||
// if (integer == 0) {
|
// if (integer == 0) {
|
||||||
// if (WiFiUtils.getInstance().isNetworkConnected()) {
|
// if (JgyUtils.getInstance().isNetworkConnected()) {
|
||||||
// Toaster.showLong("请先激活设备");
|
// Toaster.showLong("请先激活设备");
|
||||||
// startActivity(new Intent(MainActivity.this, ActivationActivity.class));
|
// startActivity(new Intent(MainActivity.this, ActivationActivity.class));
|
||||||
// }
|
// }
|
||||||
@@ -710,7 +710,7 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
|
|||||||
});
|
});
|
||||||
mViewModel.getTestApp();
|
mViewModel.getTestApp();
|
||||||
|
|
||||||
registReceiver();
|
registerReceiver();
|
||||||
initAmap();
|
initAmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1081,11 +1081,11 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
|
|||||||
// super.onRestoreInstanceState(savedInstanceState);
|
// super.onRestoreInstanceState(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registReceiver() {
|
private void registerReceiver() {
|
||||||
registNewAppReceiver();
|
registerNewAppReceiver();
|
||||||
registerSOSNumberReceiver();
|
registerSOSNumberReceiver();
|
||||||
registerUpdateDesktopReceiver();
|
registerUpdateDesktopReceiver();
|
||||||
registmUpdateAddressReceiver();
|
registerUpdateAddressReceiver();
|
||||||
registerTimeReceiver();
|
registerTimeReceiver();
|
||||||
registerMissCallReceiver();
|
registerMissCallReceiver();
|
||||||
registerPhoneStateReceiver();
|
registerPhoneStateReceiver();
|
||||||
@@ -1115,7 +1115,7 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registNewAppReceiver() {
|
private void registerNewAppReceiver() {
|
||||||
mNewAppReceiver = new NewAppReceiver();
|
mNewAppReceiver = new NewAppReceiver();
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||||
@@ -1190,7 +1190,7 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
|
|||||||
|
|
||||||
private UpdateAddressReceiver mUpdateAddressReceiver;
|
private UpdateAddressReceiver mUpdateAddressReceiver;
|
||||||
|
|
||||||
private void registmUpdateAddressReceiver() {
|
private void registerUpdateAddressReceiver() {
|
||||||
mUpdateAddressReceiver = new UpdateAddressReceiver();
|
mUpdateAddressReceiver = new UpdateAddressReceiver();
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(CommonConfig.UIUIAIOS_UPDATE_ADDRESS_ACTION);
|
filter.addAction(CommonConfig.UIUIAIOS_UPDATE_ADDRESS_ACTION);
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ import com.vscool.os.service.main.MainService;
|
|||||||
import com.vscool.os.utils.ActivationUtil;
|
import com.vscool.os.utils.ActivationUtil;
|
||||||
import com.vscool.os.utils.ApkUtils;
|
import com.vscool.os.utils.ApkUtils;
|
||||||
import com.vscool.os.utils.FileUtil;
|
import com.vscool.os.utils.FileUtil;
|
||||||
|
import com.vscool.os.utils.JgyUtils;
|
||||||
import com.vscool.os.utils.Utils;
|
import com.vscool.os.utils.Utils;
|
||||||
import com.vscool.os.utils.WiFiUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -85,7 +85,7 @@ public class MainViewModel extends BaseViewModel<ActivityMainBinding, ActivityEv
|
|||||||
boolean activation = ActivationUtil.isActivation(getCtx());
|
boolean activation = ActivationUtil.isActivation(getCtx());
|
||||||
Log.e(TAG, "getweather: is_activation = " + activation);
|
Log.e(TAG, "getweather: is_activation = " + activation);
|
||||||
if (!activation) {
|
if (!activation) {
|
||||||
if (WiFiUtils.getInstance().isNetworkConnected()) {
|
if (JgyUtils.getInstance().isNetworkConnected()) {
|
||||||
Toaster.show("请先激活设备");
|
Toaster.show("请先激活设备");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import com.vscool.os.bean.AppInfo;
|
|||||||
import com.vscool.os.bean.SystemSettings;
|
import com.vscool.os.bean.SystemSettings;
|
||||||
import com.vscool.os.config.CommonConfig;
|
import com.vscool.os.config.CommonConfig;
|
||||||
import com.vscool.os.databinding.ActivitySettingBinding;
|
import com.vscool.os.databinding.ActivitySettingBinding;
|
||||||
|
import com.vscool.os.dialog.CustomDialog;
|
||||||
import com.vscool.os.service.WeAccessibilityService;
|
import com.vscool.os.service.WeAccessibilityService;
|
||||||
import com.vscool.os.service.main.MainService;
|
import com.vscool.os.service.main.MainService;
|
||||||
import com.vscool.os.utils.AccessibilityUtils;
|
import com.vscool.os.utils.AccessibilityUtils;
|
||||||
@@ -127,7 +128,29 @@ public class SettingActivity extends BaseMvvmActivity<SettingViewModel, Activity
|
|||||||
@Override
|
@Override
|
||||||
public void onToggle(boolean on) {
|
public void onToggle(boolean on) {
|
||||||
Log.e(TAG, "setHourlyTimeSignal: hourly_time = " + on);
|
Log.e(TAG, "setHourlyTimeSignal: hourly_time = " + on);
|
||||||
mMMKV.encode(CommonConfig.HOURLY_TIME_SIGNAL_KEY, on);
|
if (on) {
|
||||||
|
CustomDialog customDialog = new CustomDialog(SettingActivity.this);
|
||||||
|
customDialog.setTitle("温馨提示")
|
||||||
|
.setMessage("整点报时时间为7点至21点")
|
||||||
|
.setOnClickBottomListener(new CustomDialog.OnClickBottomListener() {
|
||||||
|
@Override
|
||||||
|
public void onPositiveClick() {
|
||||||
|
mMMKV.encode(CommonConfig.HOURLY_TIME_SIGNAL_KEY, true);
|
||||||
|
Intent intent = new Intent(MainService.VSCOOL_ACTION_TIME_CHANGED);
|
||||||
|
sendBroadcast(intent);
|
||||||
|
customDialog.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegtiveClick() {
|
||||||
|
mViewDataBinding.tbHourly.setToggleOff();
|
||||||
|
customDialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
customDialog.show();
|
||||||
|
} else {
|
||||||
|
mMMKV.encode(CommonConfig.HOURLY_TIME_SIGNAL_KEY, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mViewDataBinding.tbVolume.setOnToggleChanged(new ToggleButton.OnToggleChanged() {
|
mViewDataBinding.tbVolume.setOnToggleChanged(new ToggleButton.OnToggleChanged() {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import com.vscool.os.databinding.ActivityWeatherBinding;
|
|||||||
import com.vscool.os.manager.AmapManager;
|
import com.vscool.os.manager.AmapManager;
|
||||||
import com.vscool.os.network.NetInterfaceManager;
|
import com.vscool.os.network.NetInterfaceManager;
|
||||||
import com.vscool.os.utils.ActivationUtil;
|
import com.vscool.os.utils.ActivationUtil;
|
||||||
import com.vscool.os.utils.WiFiUtils;
|
import com.vscool.os.utils.JgyUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public class WeatherViewModel extends BaseViewModel<ActivityWeatherBinding, Acti
|
|||||||
boolean activation = ActivationUtil.isActivation(getCtx());
|
boolean activation = ActivationUtil.isActivation(getCtx());
|
||||||
Log.e(TAG, "getweather: is_activation = " + activation);
|
Log.e(TAG, "getweather: is_activation = " + activation);
|
||||||
if (!activation) {
|
if (!activation) {
|
||||||
if (WiFiUtils.getInstance().isNetworkConnected()) {
|
if (JgyUtils.getInstance().isNetworkConnected()) {
|
||||||
Toaster.show("请先激活设备");
|
Toaster.show("请先激活设备");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ import com.vscool.os.push.PushManager;
|
|||||||
import com.vscool.os.service.main.MainService;
|
import com.vscool.os.service.main.MainService;
|
||||||
import com.vscool.os.shortcut.ShortcutUtils;
|
import com.vscool.os.shortcut.ShortcutUtils;
|
||||||
import com.vscool.os.utils.AppUsedTimeUtils;
|
import com.vscool.os.utils.AppUsedTimeUtils;
|
||||||
|
import com.vscool.os.utils.JgyUtils;
|
||||||
import com.vscool.os.utils.Utils;
|
import com.vscool.os.utils.Utils;
|
||||||
import com.vscool.os.utils.WiFiUtils;
|
|
||||||
|
|
||||||
public class BaseApplication extends Application {
|
public class BaseApplication extends Application {
|
||||||
private static final String TAG = "BaseApplication";
|
private static final String TAG = "BaseApplication";
|
||||||
@@ -45,6 +45,8 @@ public class BaseApplication extends Application {
|
|||||||
String rootDir = MMKV.initialize(this);
|
String rootDir = MMKV.initialize(this);
|
||||||
Log.e(TAG, "mmkv root: " + rootDir);
|
Log.e(TAG, "mmkv root: " + rootDir);
|
||||||
|
|
||||||
|
JgyUtils.init(this);
|
||||||
|
|
||||||
// 初始化 Toast 框架
|
// 初始化 Toast 框架
|
||||||
Toaster.init(this);
|
Toaster.init(this);
|
||||||
|
|
||||||
@@ -61,7 +63,6 @@ public class BaseApplication extends Application {
|
|||||||
Aria.get(this).getDownloadConfig().setConvertSpeed(true);
|
Aria.get(this).getDownloadConfig().setConvertSpeed(true);
|
||||||
|
|
||||||
AppManager.init(this);
|
AppManager.init(this);
|
||||||
WiFiUtils.init(this);
|
|
||||||
AppUsedTimeUtils.init(this);
|
AppUsedTimeUtils.init(this);
|
||||||
AlarmUtils.init(this);
|
AlarmUtils.init(this);
|
||||||
ShortcutUtils.init(this);
|
ShortcutUtils.init(this);
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ public class CommonConfig {
|
|||||||
/*桌面图标个数*/
|
/*桌面图标个数*/
|
||||||
public final static int DESKTOP_LIST_SIZE = DESKTOP_LAYOUT_COLUMNS_SIZE * DESKTOP_LAYOUT_ROWS_SIZE;
|
public final static int DESKTOP_LIST_SIZE = DESKTOP_LAYOUT_COLUMNS_SIZE * DESKTOP_LAYOUT_ROWS_SIZE;
|
||||||
|
|
||||||
public static final String HIDE_CALENDAR_KEY = "hide_desktop_calendar";
|
|
||||||
|
|
||||||
public static final String MAP_LOCATION_JSON_KEY = "MAPLOCATION_JSON_STRING";
|
public static final String MAP_LOCATION_JSON_KEY = "MAPLOCATION_JSON_STRING";
|
||||||
public static final String MAP_LONGITUDE_KEY = "map_longitude_key";
|
public static final String MAP_LONGITUDE_KEY = "map_longitude_key";
|
||||||
@@ -140,5 +139,7 @@ public class CommonConfig {
|
|||||||
public static final String AMAP_LOCATION_MAP_BEAN = "AMapLocation_MapBean_key";
|
public static final String AMAP_LOCATION_MAP_BEAN = "AMapLocation_MapBean_key";
|
||||||
public static final String AMAP_LOCATION_DISTRICT = "AMapLocationMapBean_key";
|
public static final String AMAP_LOCATION_DISTRICT = "AMapLocationMapBean_key";
|
||||||
|
|
||||||
|
public static final String HIDE_CALENDAR_KEY = "hide_desktop_calendar";
|
||||||
|
public static final String SHOW_LENOVO_APPSTORE = "show_lenovo_appstore";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ public class ContactViewModel extends BaseViewModel<FragmentContactHomeBinding,
|
|||||||
mContactListData.setValue(contactList);
|
mContactListData.setValue(contactList);
|
||||||
} else {
|
} else {
|
||||||
mMMKV.remove(UrlAddress.GET_MAIL_LIST);
|
mMMKV.remove(UrlAddress.GET_MAIL_LIST);
|
||||||
|
mContactListData.setValue(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import com.vscool.os.activity.main.MainActivity;
|
|||||||
import com.vscool.os.bean.DailyAppBean;
|
import com.vscool.os.bean.DailyAppBean;
|
||||||
import com.vscool.os.config.CommonConfig;
|
import com.vscool.os.config.CommonConfig;
|
||||||
import com.vscool.os.config.PackagesName;
|
import com.vscool.os.config.PackagesName;
|
||||||
import com.vscool.os.utils.ApkUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -64,15 +63,22 @@ public class AppStatusManager {
|
|||||||
Log.e(TAG, "AppStatusManager: " + stringSet);
|
Log.e(TAG, "AppStatusManager: " + stringSet);
|
||||||
this.hidedAppSet = stringSet;
|
this.hidedAppSet = stringSet;
|
||||||
|
|
||||||
if (!mMMKV.decodeBool(CommonConfig.HIDE_CALENDAR_KEY, false)) {
|
// if (!mMMKV.decodeBool(CommonConfig.HIDE_CALENDAR_KEY, false)) {
|
||||||
removeHidedApp("cn.etouch.ecalendar");
|
// removeHidedApp("cn.etouch.ecalendar");
|
||||||
addHidedApp("com.youloft.calendar");
|
// addHidedApp("com.youloft.calendar");
|
||||||
addHidedApp("com.honghui.huangli");
|
// addHidedApp("com.honghui.huangli");
|
||||||
ApkUtils.uninstall(mContext, "cn.etouch.ecalendar");
|
// ApkUtils.uninstall(mContext, "cn.etouch.ecalendar");
|
||||||
ApkUtils.disableApp(mContext, "cn.etouch.ecalendar");
|
// ApkUtils.disableApp(mContext, "cn.etouch.ecalendar");
|
||||||
mMMKV.encode(CommonConfig.HIDE_CALENDAR_KEY, true);
|
// mMMKV.encode(CommonConfig.HIDE_CALENDAR_KEY, true);
|
||||||
Log.e(TAG, "AppStatusManager: hide calendar");
|
// Log.e(TAG, "AppStatusManager: hide calendar");
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (!mMMKV.decodeBool(CommonConfig.SHOW_LENOVO_APPSTORE, false)) {
|
||||||
|
removeHidedApp("com.lenovo.leos.appstore");
|
||||||
|
mMMKV.encode(CommonConfig.SHOW_LENOVO_APPSTORE, true);
|
||||||
|
Log.e(TAG, "AppStatusManager: show appstore");
|
||||||
}
|
}
|
||||||
|
|
||||||
long oldVersionCode = mMMKV.decodeLong(CommonConfig.APP_VERSION_CODE, 0);
|
long oldVersionCode = mMMKV.decodeLong(CommonConfig.APP_VERSION_CODE, 0);
|
||||||
if (oldVersionCode == 0) {
|
if (oldVersionCode == 0) {
|
||||||
addHidedApp("com.android.stk");
|
addHidedApp("com.android.stk");
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.vscool.os.service.main;
|
package com.vscool.os.service.main;
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -46,6 +48,7 @@ import com.vscool.os.utils.ApkUtils;
|
|||||||
import com.vscool.os.utils.AppUsedTimeUtils;
|
import com.vscool.os.utils.AppUsedTimeUtils;
|
||||||
import com.vscool.os.utils.CmdUtil;
|
import com.vscool.os.utils.CmdUtil;
|
||||||
import com.vscool.os.utils.ForegroundAppUtil;
|
import com.vscool.os.utils.ForegroundAppUtil;
|
||||||
|
import com.vscool.os.utils.TimeUtils;
|
||||||
import com.vscool.os.utils.Utils;
|
import com.vscool.os.utils.Utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -91,8 +94,12 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
private WindowManager.LayoutParams mBallParams;
|
private WindowManager.LayoutParams mBallParams;
|
||||||
public boolean isBallShown = false;
|
public boolean isBallShown = false;
|
||||||
|
|
||||||
private static final String Float_Window_X = "float_window_x_key";
|
private static final String FLOAT_WINDOW_X = "float_window_x_key";
|
||||||
private static final String Float_Window_Y = "float_window_y_key";
|
private static final String FLOAT_WINDOW_Y = "float_window_y_key";
|
||||||
|
|
||||||
|
private static final int TIME_REQUEST_CODE = 9999;
|
||||||
|
private static final String VSCOOL_ACTION_TIME_TICK = "vscool_time_tick";
|
||||||
|
public static final String VSCOOL_ACTION_TIME_CHANGED = "vscool_time_changed";
|
||||||
|
|
||||||
public MainService() {
|
public MainService() {
|
||||||
|
|
||||||
@@ -213,9 +220,6 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
mPresenter.addAlarmClock();
|
mPresenter.addAlarmClock();
|
||||||
|
|
||||||
long oldVersionCode = mMMKV.decodeLong(CommonConfig.APP_VERSION_CODE, 0);
|
long oldVersionCode = mMMKV.decodeLong(CommonConfig.APP_VERSION_CODE, 0);
|
||||||
if (oldVersionCode == 1038) {
|
|
||||||
|
|
||||||
}
|
|
||||||
if (oldVersionCode < BuildConfig.VERSION_CODE) {
|
if (oldVersionCode < BuildConfig.VERSION_CODE) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -223,8 +227,10 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
}
|
}
|
||||||
mMMKV.encode(CommonConfig.APP_VERSION_CODE, BuildConfig.VERSION_CODE);
|
mMMKV.encode(CommonConfig.APP_VERSION_CODE, BuildConfig.VERSION_CODE);
|
||||||
|
|
||||||
|
setAlarmTime();
|
||||||
|
registerTimeChangedReceiver();
|
||||||
|
|
||||||
registerAlarmReceiver();
|
registerAlarmReceiver();
|
||||||
registerTimeReceiver();
|
|
||||||
registFastCallReceive();
|
registFastCallReceive();
|
||||||
registerLockScreenReceiver();
|
registerLockScreenReceiver();
|
||||||
registerOperateAlarmClockReceiver();
|
registerOperateAlarmClockReceiver();
|
||||||
@@ -250,7 +256,9 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
public void onNext(@NonNull Integer hour) {
|
public void onNext(@NonNull Integer hour) {
|
||||||
Log.e("mTimeSignalCallback", "onNext: ");
|
Log.e("mTimeSignalCallback", "onNext: ");
|
||||||
mWakeLock.acquire(60 * 1000L);
|
mWakeLock.acquire(60 * 1000L);
|
||||||
mSoundPool.play(soundMap.get(hour), 1, 1, 0, 0, 1);
|
if (hour > 6 && hour < 22) {
|
||||||
|
mSoundPool.play(soundMap.get(hour), 1, 1, 0, 0, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -265,6 +273,34 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setAlarmTime() {
|
||||||
|
/*Android 10 及以后息屏收不到time_tick广播*/
|
||||||
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
|
||||||
|
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||||
|
Intent intent = new Intent(VSCOOL_ACTION_TIME_TICK);
|
||||||
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, TIME_REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
long triggerAtTime = getIntervalMillis();
|
||||||
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAtTime, pendingIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 获取下个整点的时间戳
|
||||||
|
*/
|
||||||
|
private long getIntervalMillis() {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||||
|
Log.e(TAG, "getIntervalMillis: hour = " + hour);
|
||||||
|
int min = calendar.get(Calendar.MINUTE);
|
||||||
|
Log.e(TAG, "getIntervalMillis: min = " + min);
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, hour + 1);
|
||||||
|
calendar.set(Calendar.MINUTE, 0);
|
||||||
|
calendar.set(Calendar.SECOND, 0);
|
||||||
|
long time = calendar.getTimeInMillis();
|
||||||
|
Log.e(TAG, "getIntervalMillis: time = " + TimeUtils.transferLongToDate(time));
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
Log.e(TAG, "onStartCommand: ");
|
Log.e(TAG, "onStartCommand: ");
|
||||||
@@ -299,6 +335,7 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
Log.e(TAG, "onDestroy: ");
|
||||||
mPresenter.detachView();
|
mPresenter.detachView();
|
||||||
NetworkUtils.unregisterNetworkStatusChangedListener(this);
|
NetworkUtils.unregisterNetworkStatusChangedListener(this);
|
||||||
if (alarmReceiver != null) {
|
if (alarmReceiver != null) {
|
||||||
@@ -403,7 +440,7 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 监听时间和日期变化
|
// 监听时间和日期变化
|
||||||
public void registerTimeReceiver() {
|
public void registerTimeChangedReceiver() {
|
||||||
mTimeChangedReceiver = new TimeChangedReceiver();
|
mTimeChangedReceiver = new TimeChangedReceiver();
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||||
@@ -411,6 +448,8 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||||
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||||
filter.addAction(Intent.ACTION_TIME_TICK);
|
filter.addAction(Intent.ACTION_TIME_TICK);
|
||||||
|
filter.addAction(VSCOOL_ACTION_TIME_TICK);
|
||||||
|
filter.addAction(VSCOOL_ACTION_TIME_CHANGED);
|
||||||
registerReceiver(mTimeChangedReceiver, filter);
|
registerReceiver(mTimeChangedReceiver, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,20 +459,21 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
switch (intent.getAction()) {
|
String action = intent.getAction();
|
||||||
|
Log.e("TimeChangedReceiver", "onReceive: " + action);
|
||||||
|
switch (action) {
|
||||||
case Intent.ACTION_DATE_CHANGED:
|
case Intent.ACTION_DATE_CHANGED:
|
||||||
Log.e(TAG, "TimeChangedReceiver:" + "data changed");
|
|
||||||
break;
|
|
||||||
case Intent.ACTION_TIME_CHANGED:
|
case Intent.ACTION_TIME_CHANGED:
|
||||||
Log.e(TAG, "TimeChangedReceiver:" + "time changed");
|
|
||||||
break;
|
|
||||||
case Intent.ACTION_TIMEZONE_CHANGED:
|
case Intent.ACTION_TIMEZONE_CHANGED:
|
||||||
Log.e(TAG, "TimeChangedReceiver:" + "timezone changed");
|
case VSCOOL_ACTION_TIME_CHANGED:
|
||||||
|
setAlarmTime();
|
||||||
break;
|
break;
|
||||||
case Intent.ACTION_TIME_TICK:
|
case Intent.ACTION_TIME_TICK:
|
||||||
Log.e(TAG, "TimeChangedReceiver:" + "time tick");
|
|
||||||
hourlyTimeSignal();
|
hourlyTimeSignal();
|
||||||
break;
|
break;
|
||||||
|
case VSCOOL_ACTION_TIME_TICK:
|
||||||
|
alarmWakeup();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -448,10 +488,10 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
private void hourlyTimeSignal() {
|
private void hourlyTimeSignal() {
|
||||||
boolean hourly_time = mMMKV.decodeBool(CommonConfig.HOURLY_TIME_SIGNAL_KEY, false);
|
boolean hourly_time = mMMKV.decodeBool(CommonConfig.HOURLY_TIME_SIGNAL_KEY, false);
|
||||||
if (hourly_time) {
|
if (hourly_time) {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
int hour = cal.get(Calendar.HOUR_OF_DAY);
|
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||||
Log.e(TAG, "hourlyTimeSignal: hour = " + hour);
|
Log.e(TAG, "hourlyTimeSignal: hour = " + hour);
|
||||||
int min = cal.get(Calendar.MINUTE);
|
int min = calendar.get(Calendar.MINUTE);
|
||||||
Log.e(TAG, "hourlyTimeSignal: min = " + min);
|
Log.e(TAG, "hourlyTimeSignal: min = " + min);
|
||||||
if (min == 0) {
|
if (min == 0) {
|
||||||
mTimeSignalCallback.timeTick(hour);
|
mTimeSignalCallback.timeTick(hour);
|
||||||
@@ -461,6 +501,19 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void alarmWakeup() {
|
||||||
|
boolean hourly_time = mMMKV.decodeBool(CommonConfig.HOURLY_TIME_SIGNAL_KEY, false);
|
||||||
|
if (hourly_time) {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||||
|
Log.e(TAG, "hourlyTimeSignal: hour = " + hour);
|
||||||
|
mTimeSignalCallback.timeTick(hour);
|
||||||
|
setAlarmTime();
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "hourlyTimeSignal: not enable hourly time signal");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void registFastCallReceive() {
|
private void registFastCallReceive() {
|
||||||
if (null == mTimeSignalReceiver) {
|
if (null == mTimeSignalReceiver) {
|
||||||
mTimeSignalReceiver = new TimeSignalReceiver();
|
mTimeSignalReceiver = new TimeSignalReceiver();
|
||||||
@@ -734,8 +787,8 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
if (mBallView.isAttachedToWindow()) {
|
if (mBallView.isAttachedToWindow()) {
|
||||||
mWindowManager.removeView(mBallView);
|
mWindowManager.removeView(mBallView);
|
||||||
}
|
}
|
||||||
mMMKV.encode(Float_Window_X, mBallParams.x);
|
mMMKV.encode(FLOAT_WINDOW_X, mBallParams.x);
|
||||||
mMMKV.encode(Float_Window_Y, mBallParams.y);
|
mMMKV.encode(FLOAT_WINDOW_Y, mBallParams.y);
|
||||||
}
|
}
|
||||||
isBallShown = false;
|
isBallShown = false;
|
||||||
break;
|
break;
|
||||||
@@ -795,8 +848,8 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
mBallParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
mBallParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||||
mBallParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
mBallParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||||
// mBallParams.gravity = Gravity.TOP;
|
// mBallParams.gravity = Gravity.TOP;
|
||||||
int x = mMMKV.decodeInt(Float_Window_X, 360);
|
int x = mMMKV.decodeInt(FLOAT_WINDOW_X, 360);
|
||||||
int y = mMMKV.decodeInt(Float_Window_Y, -783);
|
int y = mMMKV.decodeInt(FLOAT_WINDOW_Y, -783);
|
||||||
mBallParams.x = x;
|
mBallParams.x = x;
|
||||||
mBallParams.y = y;
|
mBallParams.y = y;
|
||||||
mWindowManager.addView(mBallView, mBallParams);
|
mWindowManager.addView(mBallView, mBallParams);
|
||||||
@@ -885,8 +938,8 @@ public class MainService extends BaseRxService implements MainSContact.MainSView
|
|||||||
mBallParams.y += tranY;
|
mBallParams.y += tranY;
|
||||||
// 更新悬浮窗位置
|
// 更新悬浮窗位置
|
||||||
mWindowManager.updateViewLayout(mBallView, mBallParams);
|
mWindowManager.updateViewLayout(mBallView, mBallParams);
|
||||||
mMMKV.encode(Float_Window_X, mBallParams.x);
|
mMMKV.encode(FLOAT_WINDOW_X, mBallParams.x);
|
||||||
mMMKV.encode(Float_Window_Y, mBallParams.y);
|
mMMKV.encode(FLOAT_WINDOW_Y, mBallParams.y);
|
||||||
// 记录当前坐标作为下一次计算的上一次移动的位置坐标
|
// 记录当前坐标作为下一次计算的上一次移动的位置坐标
|
||||||
lastX = nowX;
|
lastX = nowX;
|
||||||
lastY = nowY;
|
lastY = nowY;
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ public class ApkUtils {
|
|||||||
resolveInfos.add(resolveInfo);
|
resolveInfos.add(resolveInfo);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ("com.android.mms".equals(pkg)) {
|
if ("com.android.mms".equals(pkg) || "com.lenovo.leos.appstore".equals(pkg)) {
|
||||||
resolveInfos.add(resolveInfo);
|
resolveInfos.add(resolveInfo);
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "getAppstoreAppInfo: pkgSet ! contains " + pkg);
|
Log.e(TAG, "getAppstoreAppInfo: pkgSet ! contains " + pkg);
|
||||||
|
|||||||
103
app/src/main/java/com/vscool/os/utils/JgyUtils.java
Normal file
103
app/src/main/java/com/vscool/os/utils/JgyUtils.java
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package com.vscool.os.utils;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class JgyUtils {
|
||||||
|
private static String TAG = "JgyUtils";
|
||||||
|
|
||||||
|
private static JgyUtils sInstance;
|
||||||
|
private static WifiManager mWifiManager;
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
public JgyUtils(Context context) {
|
||||||
|
this.mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init(Context context) {
|
||||||
|
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||||
|
if (sInstance == null) {
|
||||||
|
Log.e(TAG, "init: ");
|
||||||
|
sInstance = new JgyUtils(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JgyUtils getInstance() {
|
||||||
|
if (sInstance == null) {
|
||||||
|
throw new IllegalStateException("You must be init JgyUtils first");
|
||||||
|
}
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIMEI() {
|
||||||
|
String IMEI = "unknown";
|
||||||
|
String IMEI1, IMEI2, IMEI3;
|
||||||
|
//获取手机设备号
|
||||||
|
TelephonyManager TelephonyMgr = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
//8.0及以后版本获取
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
IMEI = TelephonyMgr.getDeviceId();
|
||||||
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
// try {
|
||||||
|
// Method method = TelephonyMgr.getClass().getMethod("getImei");
|
||||||
|
// IMEI = (String) method.invoke(TelephonyMgr);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// Log.e("getIMEI", e.getMessage());
|
||||||
|
// }
|
||||||
|
// IMEI = TelephonyMgr.getDeviceId();
|
||||||
|
|
||||||
|
// } else {//9.0到10.0获取
|
||||||
|
IMEI = Settings.System.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||||
|
}
|
||||||
|
// Log.e("IMEI:", "IMEI: " + IMEI);
|
||||||
|
if (null == IMEI) {
|
||||||
|
return "-";
|
||||||
|
} else {
|
||||||
|
return IMEI.toUpperCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wifi是否打开
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isWifiEnable() {
|
||||||
|
boolean isEnable = false;
|
||||||
|
if (mWifiManager != null) {
|
||||||
|
if (mWifiManager.isWifiEnabled()) {
|
||||||
|
isEnable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断网络连接状态
|
||||||
|
*
|
||||||
|
* @return true:网络已链接, false:网络已断开连接
|
||||||
|
*/
|
||||||
|
public boolean isNetworkConnected() {
|
||||||
|
if (mContext != null) {
|
||||||
|
ConnectivityManager mConnectivityManager = (ConnectivityManager) mContext
|
||||||
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
NetworkInfo mNetworkInfo = mConnectivityManager
|
||||||
|
.getActiveNetworkInfo();
|
||||||
|
if (mNetworkInfo != null) {
|
||||||
|
return mNetworkInfo.isAvailable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -43,13 +43,17 @@ import java.util.function.Consumer;
|
|||||||
public class Utils {
|
public class Utils {
|
||||||
private static final String TAG = "Utils";
|
private static final String TAG = "Utils";
|
||||||
|
|
||||||
|
public static String getSerial() {
|
||||||
|
return JgyUtils.getInstance().getIMEI();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取设备序列号
|
* 获取设备序列号
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
public static String getSerial() {
|
public static String getSn() {
|
||||||
String serial = "unknow";
|
String serial = "unknow";
|
||||||
try {
|
try {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {//9.0+
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {//9.0+
|
||||||
|
|||||||
@@ -1,241 +0,0 @@
|
|||||||
package com.vscool.os.utils;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.net.wifi.ScanResult;
|
|
||||||
import android.net.wifi.WifiConfiguration;
|
|
||||||
import android.net.wifi.WifiInfo;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author : fanhuitong
|
|
||||||
* e-mail :
|
|
||||||
* @date : 2021/10/25 10:20
|
|
||||||
* desc :
|
|
||||||
* version: 1.0
|
|
||||||
*/
|
|
||||||
public class WiFiUtils {
|
|
||||||
private static WiFiUtils sInstance;
|
|
||||||
private static WifiManager mWifiManager;
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
|
||||||
private Context mContext;
|
|
||||||
private static String TAG = "WiFiUtils";
|
|
||||||
|
|
||||||
public WiFiUtils(Context context) {
|
|
||||||
this.mContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void init(Context context) {
|
|
||||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
|
||||||
if (sInstance == null) {
|
|
||||||
Log.e(TAG, "init: ");
|
|
||||||
sInstance = new WiFiUtils(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static WiFiUtils getInstance() {
|
|
||||||
if (sInstance == null) {
|
|
||||||
throw new IllegalStateException("You must be init WiFiUtils first");
|
|
||||||
}
|
|
||||||
return sInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wifi是否打开
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isWifiEnable() {
|
|
||||||
boolean isEnable = false;
|
|
||||||
if (mWifiManager != null) {
|
|
||||||
if (mWifiManager.isWifiEnabled()) {
|
|
||||||
isEnable = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return isEnable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打开WiFi
|
|
||||||
*/
|
|
||||||
public void openWifi() {
|
|
||||||
if (mWifiManager != null && !isWifiEnable()) {
|
|
||||||
mWifiManager.setWifiEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关闭WiFi
|
|
||||||
*/
|
|
||||||
public void closeWifi() {
|
|
||||||
if (mWifiManager != null && isWifiEnable()) {
|
|
||||||
mWifiManager.setWifiEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取WiFi列表
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public List<ScanResult> getWifiList() {
|
|
||||||
List<ScanResult> resultList = new ArrayList<>();
|
|
||||||
if (mWifiManager != null && isWifiEnable()) {
|
|
||||||
resultList.addAll(mWifiManager.getScanResults());
|
|
||||||
}
|
|
||||||
return resultList;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 有密码连接
|
|
||||||
*
|
|
||||||
* @param ssid
|
|
||||||
* @param pws
|
|
||||||
*/
|
|
||||||
public static void connectWifiPws(String ssid, String pws) {
|
|
||||||
// mWifiManager.disableNetwork(mWifiManager.getConnectionInfo().getNetworkId());
|
|
||||||
mWifiManager.disconnect();
|
|
||||||
int netId = mWifiManager.addNetwork(getWifiConfig(ssid, pws, true));
|
|
||||||
mWifiManager.enableNetwork(netId, true);
|
|
||||||
mWifiManager.reconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 无密码连接
|
|
||||||
*
|
|
||||||
* @param ssid
|
|
||||||
*/
|
|
||||||
public void connectWifiNoPws(String ssid) {
|
|
||||||
// mWifiManager.disableNetwork(mWifiManager.getConnectionInfo().getNetworkId());
|
|
||||||
int netId = mWifiManager.addNetwork(getWifiConfig(ssid, "", false));
|
|
||||||
mWifiManager.enableNetwork(netId, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wifi设置
|
|
||||||
*
|
|
||||||
* @param ssid
|
|
||||||
* @param pws
|
|
||||||
* @param isHasPws
|
|
||||||
*/
|
|
||||||
private static WifiConfiguration getWifiConfig(String ssid, String pws, boolean isHasPws) {
|
|
||||||
WifiConfiguration config = new WifiConfiguration();
|
|
||||||
config.allowedAuthAlgorithms.clear();
|
|
||||||
config.allowedGroupCiphers.clear();
|
|
||||||
config.allowedKeyManagement.clear();
|
|
||||||
config.allowedPairwiseCiphers.clear();
|
|
||||||
config.allowedProtocols.clear();
|
|
||||||
config.SSID = "\"" + ssid + "\"";
|
|
||||||
|
|
||||||
WifiConfiguration tempConfig = isExist(ssid);
|
|
||||||
if (tempConfig != null) {
|
|
||||||
mWifiManager.removeNetwork(tempConfig.networkId);
|
|
||||||
}
|
|
||||||
if (isHasPws) {
|
|
||||||
config.preSharedKey = "\"" + pws + "\"";
|
|
||||||
config.hiddenSSID = true;
|
|
||||||
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
|
|
||||||
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
|
|
||||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
|
|
||||||
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
|
|
||||||
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
|
|
||||||
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
|
|
||||||
config.status = WifiConfiguration.Status.ENABLED;
|
|
||||||
} else {
|
|
||||||
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 得到配置好的网络连接
|
|
||||||
*
|
|
||||||
* @param ssid
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static WifiConfiguration isExist(String ssid) {
|
|
||||||
List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
|
|
||||||
for (WifiConfiguration config : configs) {
|
|
||||||
if (config.SSID.equals("\"" + ssid + "\"")) {
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addWiFiNetwork(String ssid, String passwd) {
|
|
||||||
int netId;
|
|
||||||
if (TextUtils.isEmpty(passwd)) {
|
|
||||||
netId = mWifiManager.addNetwork(getWifiConfig(ssid, "", false));
|
|
||||||
} else {
|
|
||||||
netId = mWifiManager.addNetwork(getWifiConfig(ssid, passwd, true));
|
|
||||||
}
|
|
||||||
mWifiManager.enableNetwork(netId, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeWiFiNetwork(String ssid) {
|
|
||||||
WifiConfiguration tempConfig = isExist(ssid);
|
|
||||||
int networkId = tempConfig.networkId;
|
|
||||||
mWifiManager.removeNetwork(networkId);
|
|
||||||
mWifiManager.saveConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized private static boolean wifiSaved(String ssid) {
|
|
||||||
// 获取已保存wifi配置链表
|
|
||||||
List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
|
|
||||||
boolean saved = false;
|
|
||||||
for (WifiConfiguration configuration : configs) {
|
|
||||||
if (ssid.equals(configuration.SSID)) {
|
|
||||||
saved = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return saved;
|
|
||||||
}
|
|
||||||
|
|
||||||
//断判某个wifi是否是连接成功的那个wifi
|
|
||||||
public boolean isConnectedWifi(Context context, String myssid) {
|
|
||||||
WifiManager mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
|
||||||
if (isWifiConnect(context)) {
|
|
||||||
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
|
|
||||||
String ssid = wifiInfo.getSSID();
|
|
||||||
return ssid != null && ssid.contains(myssid);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//判断wifi是否连接
|
|
||||||
public static boolean isWifiConnect(Context context) {
|
|
||||||
ConnectivityManager connManager = (ConnectivityManager) context
|
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
@SuppressLint("MissingPermission")
|
|
||||||
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
|
||||||
return mWifi.getState() == NetworkInfo.State.CONNECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断网络连接状态
|
|
||||||
*
|
|
||||||
* @return true:网络已链接, false:网络已断开连接
|
|
||||||
*/
|
|
||||||
public boolean isNetworkConnected() {
|
|
||||||
if (mContext != null) {
|
|
||||||
ConnectivityManager mConnectivityManager = (ConnectivityManager) mContext
|
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
NetworkInfo mNetworkInfo = mConnectivityManager
|
|
||||||
.getActiveNetworkInfo();
|
|
||||||
if (mNetworkInfo != null) {
|
|
||||||
return mNetworkInfo.isAvailable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user