use of androidx.annotation.RequiresPermission in project AndroidUtilCode by Blankj.
the class NetworkUtils method getSSID.
/**
* Return the ssid.
*
* @return the ssid.
*/
@RequiresPermission(ACCESS_WIFI_STATE)
public static String getSSID() {
WifiManager wm = (WifiManager) Utils.getApp().getApplicationContext().getSystemService(WIFI_SERVICE);
if (wm == null)
return "";
WifiInfo wi = wm.getConnectionInfo();
if (wi == null)
return "";
String ssid = wi.getSSID();
if (TextUtils.isEmpty(ssid)) {
return "";
}
if (ssid.length() > 2 && ssid.charAt(0) == '"' && ssid.charAt(ssid.length() - 1) == '"') {
return ssid.substring(1, ssid.length() - 1);
}
return ssid;
}
use of androidx.annotation.RequiresPermission in project AndroidUtilCode by Blankj.
the class NetworkUtils method startScanWifiIfEnabled.
@RequiresPermission(allOf = { ACCESS_WIFI_STATE, CHANGE_WIFI_STATE })
private static void startScanWifiIfEnabled() {
if (!getWifiEnabled())
return;
@SuppressLint("WifiManagerLeak") WifiManager wm = (WifiManager) Utils.getApp().getSystemService(WIFI_SERVICE);
// noinspection ConstantConditions
wm.startScan();
}
use of androidx.annotation.RequiresPermission in project AndroidUtilCode by Blankj.
the class ProcessUtils method killAllBackgroundProcesses.
/**
* Kill all background processes.
* <p>Must hold {@code <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />}</p>
*
* @return background processes were killed
*/
@RequiresPermission(KILL_BACKGROUND_PROCESSES)
public static Set<String> killAllBackgroundProcesses() {
ActivityManager am = (ActivityManager) Utils.getApp().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> info = am.getRunningAppProcesses();
Set<String> set = new HashSet<>();
if (info == null)
return set;
for (ActivityManager.RunningAppProcessInfo aInfo : info) {
for (String pkg : aInfo.pkgList) {
am.killBackgroundProcesses(pkg);
set.add(pkg);
}
}
info = am.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo aInfo : info) {
for (String pkg : aInfo.pkgList) {
set.remove(pkg);
}
}
return set;
}
use of androidx.annotation.RequiresPermission in project AndroidUtilCode by Blankj.
the class VibrateUtils method vibrate.
/**
* Vibrate.
* <p>Must hold {@code <uses-permission android:name="android.permission.VIBRATE" />}</p>
*
* @param pattern An array of longs of times for which to turn the vibrator on or off.
* @param repeat The index into pattern at which to repeat, or -1 if you don't want to repeat.
*/
@RequiresPermission(VIBRATE)
public static void vibrate(final long[] pattern, final int repeat) {
Vibrator vibrator = getVibrator();
if (vibrator == null)
return;
vibrator.vibrate(pattern, repeat);
}
use of androidx.annotation.RequiresPermission in project AndroidUtilCode by Blankj.
the class NetworkUtils method setWifiEnabled.
/**
* Enable or disable wifi.
* <p>Must hold {@code <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />}</p>
*
* @param enabled True to enabled, false otherwise.
*/
@RequiresPermission(CHANGE_WIFI_STATE)
public static void setWifiEnabled(final boolean enabled) {
@SuppressLint("WifiManagerLeak") WifiManager manager = (WifiManager) Utils.getApp().getSystemService(WIFI_SERVICE);
if (manager == null)
return;
if (enabled == manager.isWifiEnabled())
return;
manager.setWifiEnabled(enabled);
}
Aggregations