Last active
July 1, 2020 11:37
-
-
Save Flywith24/35b376bc3f5d7e5b2a440e6cb5e9649e to your computer and use it in GitHub Desktop.
Framework 层常用定制功能 Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
这里记录了 Framework 定制的常用方法 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun screenCapture(context: Context) { | |
val screenPath = | |
"${context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)?.absolutePath}/ScreenCaps/" | |
val path = "$screenPath/ScreenCap_${System.currentTimeMillis()}.png" | |
val file = File(screenPath) | |
if (!file.exists()) { | |
file.mkdir() | |
} | |
Runtime.getRuntime().exec("screencap -p $path") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//清空全部 | |
fun clearAll(){ | |
// 9.0 后删除了 ActivityManager 的 removeTask() 方法 | |
//import android.app.ActivityTaskManager.getService | |
//清空最近任务 | |
getService().removeAllVisibleRecentTasks() | |
} | |
//根据包名清理 | |
fun clearPackage(packageName : String){ | |
val manager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager | |
val recentTasks = manager.getRecentTasks(Int.MAX_VALUE, ActivityManager.RECENT_WITH_EXCLUDED) | |
recentTasks.forEach { task -> | |
if(packageName == task.baseIntent.component?.packageName){ | |
getService().removeTask(task.taskId) | |
return | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment