Android 实现系统深度休眠笔记,android编程软件

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 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() {

尾声

开发是需要一定的基础的,我是08年开始进入Android这行的,在这期间经历了Android的鼎盛时期,和所谓的Android”凉了“。中间当然也有着,不可说的心酸,看着身边朋友,同事一个个转前端,换行业,其实当时我的心也有过犹豫,但是我还是坚持下来了,这次的疫情就是一个好的机会,大浪淘沙,优胜劣汰。再等等,说不定下一个黄金浪潮就被你等到了。

这是我在这行工作10几年积累的一些资料,如果还想继续在这行业走下去的,或者现在打算跳槽,可以**私信【学习】**我愿意把资料免费分享给大家。
或者直接点击下面链接领取
Android学习PDF+架构视频+面试文档+源码笔记

  • 330页 PDF Android核心笔记

Android 实现系统深度休眠笔记,android编程软件_第1张图片

  • 几十套阿里 、字节跳动、腾讯、华为、美团等公司2020年的面试题

Android 实现系统深度休眠笔记,android编程软件_第2张图片

Android 实现系统深度休眠笔记,android编程软件_第3张图片

  • PDF和思维脑图,包含知识脉络 + 诸多细节

Android 实现系统深度休眠笔记,android编程软件_第4张图片

  • Android进阶系统学习视频
    B%98%E8%96%AA%EF%BC%81.md)

  • 330页 PDF Android核心笔记

[外链图片转存中…(img-VKjA1sKP-1646221049360)]

  • 几十套阿里 、字节跳动、腾讯、华为、美团等公司2020年的面试题

[外链图片转存中…(img-ohbiixc6-1646221049361)]

[外链图片转存中…(img-7pyDPypk-1646221049362)]

  • PDF和思维脑图,包含知识脉络 + 诸多细节

[外链图片转存中…(img-LglHct5O-1646221049363)]

  • Android进阶系统学习视频

你可能感兴趣的:(程序员,面试,移动开发,android)