然后执行对应的操作:
/**
- 当前是否开启飞行模式
*/
private boolean isAirplaneModeOn(Context context) {
// 返回值是1时表示处于飞行模式
int modeIdx = Settings.Global.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0);
boolean isEnabled = (modeIdx == 1);
//MyLog.v(“[SleepReceiver]isAirplaneModeOn:” + isEnabled);
return isEnabled;
}
/**
- 设置飞行模式
*/
private void setAirplaneMode(boolean setAirPlane, Context context) { Settings.Global.putInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, setAirPlane ? 1 : 0);
// 广播飞行模式的改变,让相应的程序可以处理。
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra(“state”, setAirPlane);
context.sendBroadcast(intent);
}
- 根据包名杀死后台应用:
public void killAppByPackageName(String package){
ActivityManager myActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> mRunningPros = myActivityManager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo amPro : mRunningPros){
if(amPro.processName.contains(package)){
try {
Method forceStopPackage = myActivityManager.getClass().getDeclaredMethod(“forceStopPackage”, String.class);
forceStopPackage.setAccessible(true);
forceStopPackage.invoke(myActivityManager, amPro.processName);
}
catch (Exception e) {
}
}
}
- 媒体/铃声声音静音,需要保存休眠前的音量,供唤醒后恢复:
if (Constant.Module.muteWhenSleep) {
int volumeMusic = audioManager .getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int volumeRing = audioManager .getStreamVolume(AudioManager.STREAM_RING);
editor.putInt(“volumeMusic”, volumeMusic);
editor.putInt(“volumeRing”, volumeRing);
editor.commit();
}
- 关闭/打开GPS
context.sendBroadcast(new Intent(
“tchip.intent.action.ACTION_GPS_OFF”));
private static boolean getGpsState(Context context) {
ContentResolver resolver = context.getContentResolver();
boolean gpsState = Settings.Secure.isLocationProviderEnabled(resolver,
LocationManager.GPS_PROVIDER);
Log.v(“ZMS”, “[GPS]Now State:” + gpsState);
return gpsState;
}
private void setGpsState(Context context, boolean isGpsOn) {
ContentResolver resolver = context.getContentResolver();
boolean nowState = getGpsState(context);
if (isGpsOn != nowState) {
Log.v(“ZMS”, “[GPS]Set State:” + isGpsOn);
Settings.Secure.setLocationProviderEnabled(resolver,
LocationManager.GPS_PROVIDER, isGpsOn);
}
}
- 停止录像预览,释放recorder:由于熄屏时,不会触发SurfaceView的surfaceDestroy,所以将destroy的过程移动到Activity的onPause中执行
private void releaseCameraZone() {
release();
// mHolder = null;
if (mCamera != null) {
mCamera.stopPreview();
}
MyApplication.shouldResetRecordWhenResume = true;
}
public void release() {
releaseRecorder();
closeCamera();
}
private void releaseRecorder() {
if (mMyRecorder != null) {
mMyRecorder.stop();
mMyRecorder.close();
mMyRecorder.release();
mMyRecorder = null;
MyLog.d(“Record Release”);
}
}
private boolean closeCamera() {
if (mCamera == null)
return true;
try {
mCamera.lock();
mCamera.stopPreview();
mCamera.setPreviewDisplay(null);
mCamera.release();
mCamera.unlock();
mCamera = null;
return true;
} catch (Exception ex) {
mCamera = null;
return false;
}
}
唤醒
–
- 摄像头预览区域重新绘制,在Activity的onResume中判断是否需要执行:
if (!MyApplication.isFirstLaunch) {
if (!MyApplication.isVideoReording
|| MyApplication.shouldResetRecordWhenResume) {
MyApplication.shouldResetRecordWhenResume = false;
// 重置预览区域
if (mCamera == null) {
// mHolder = holder;
setup();
} else {
try {
mCamera.lock();
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
mCamera.unlock();
} catch (Exception e) {
// e.printStackTrace();
}
}
}
} else {
MyApplication.isFirstLaunch = false;
}
public void setup() {
release();
if (openCamera()) {
setupRecorder();
}
}
- 点亮屏幕
/**
-
点亮屏幕
-
@param context
*/
public static void lightScreen(Context context) {
// 获取电源管理器对象
PowerManager pm = (PowerManager) context
总结
我最近从朋友那里收集到了2020-2021BAT 面试真题解析,内容很多也很系统,包含了很多内容:Android 基础、Java 基础、Android 源码相关分析、常见的一些原理性问题
等等,可以很好地帮助大家深刻理解Android相关知识点的原理以及面试相关知识。
这份资料把大厂面试中常被问到的技术点整理成了PDF,包知识脉络 + 诸多细节;还有 高级架构技术进阶脑图 帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。
这里也分享给广大面试同胞们,希望每位程序猿们都能面试成功~
Android 基础知识点
Java 基础知识点
Android 源码相关分析
常见的一些原理性问题
腾讯、字节跳动、阿里、百度等BAT大厂 2019-2020面试真题解析
参考docs.qq.com/doc/DSkNLaERkbnFoS0ZF
面试同胞们,希望每位程序猿们都能面试成功~
Android 基础知识点
[外链图片转存中…(img-Tu7Prnn2-1724443798335)]
Java 基础知识点
[外链图片转存中…(img-6fUiIPyp-1724443798336)]
Android 源码相关分析
[外链图片转存中…(img-ph563GTI-1724443798336)]
常见的一些原理性问题
[外链图片转存中…(img-1VsPTum2-1724443798337)]
腾讯、字节跳动、阿里、百度等BAT大厂 2019-2020面试真题解析
[外链图片转存中…(img-7gPshztD-1724443798337)]
参考docs.qq.com/doc/DSkNLaERkbnFoS0ZF