然后执行对应的操作:
/**
- 当前是否开启飞行模式
*/
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();
总结
其实要轻松掌握很简单,要点就两个:
- 找到一套好的视频资料,紧跟大牛梳理好的知识框架进行学习。
- 多练。 (视频优势是互动感强,容易集中注意力)
你不需要是天才,也不需要具备强悍的天赋,只要做到这两点,短期内成功的概率是非常高的。
对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。下面资料部分截图是我花费几个月时间整理的,诚意满满:特别适合有3-5年开发经验的Android程序员们学习。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
分截图是我花费几个月时间整理的,诚意满满:特别适合有3-5年开发经验的Android程序员们学习。**
[外链图片转存中…(img-anO4jW9i-1714313920128)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!