我正在使用以下代码段(RunningTaskInfo)显示吐司,如果除了我的项目之外的任何应用程序启动但是,我似乎无法找到白名单启动器应用程序的方法。它总是显示吐司,即使我的启动器是打开的,没有其他应用程序打开。那里有数百个发射器(包括库存和第三方)
public static void getScreenState(Context c){
PowerManager pm = (PowerManager) c.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
if(isScreenOn){
ActivityManager manager = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(Integer.MAX_VALUE);
RunningTaskInfo info = runningTaskInfos.get(0);
String nowPackageName = info.baseActivity.getPackageName();
if(nowPackageName.equals("com.example.detectapplaunch")){
// return ScreenState.MYAPP;
}else{
// return ScreenState.OTHERAPP;
Toast.makeText(c, " warning", Toast.LENGTH_LONG).show();
}
// Log.e("MyUtils",nowPackageName);
}else{
// Log.e("isScreenOn:",String.valueOf(isScreenOn));
//return ScreenState.LOCK;
}
}
}