-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
方法4,queryUsageStats偶尔返回空集合,导致return false认为并不在前台(其实在) #17
Comments
抱歉,新年工作第一天, 忙不过来,没有及时回复您的邮件。关于你提到的问题,由于代码太久远,我需要一些时间来review一下逻辑,在review完成后会对你的问题进行答复,希望见谅。
[email protected]
发件人: 词汇族
发送时间: 2017-02-03 15:58
收件人: wenmingvs/AndroidProcess
抄送: Subscribed
主题: [wenmingvs/AndroidProcess] 方法4,queryUsageStats偶尔返回空集合,导致return false认为并不在前台(其实在) (#17)
我这样改了下就好了。
原:
/*
if (usageStats == null || usageStats.size() == 0) {
if (HavaPermissionForTest(context) == false) {
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
Toast.makeText(context, "权限不够\n请打开手机设置,点击安全-高级,在有权查看使用情况的应用中,为这个App打上勾", Toast.LENGTH_SHORT).show();
}
//发现造成这里的false 是因为 usageStats.size() == 0,即空集合(实际手机有任务存在)
// boolean r = (usageStats == null);
//android.util.Log.e("Current","usageStats:null:"+r);
return false;
}*/
改后:
//改一下上面的
if (usageStats == null || usageStats.size() == 0) {
if (HavaPermissionForTest(context) == false) {
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
//1.我是子线程里使用Toast
Looper.prepare();
Toast.makeText(context, "权限不够\n请打开手机设置,点击安全-高级,在有权查看使用情况的应用中,为这个App打上勾", Toast.LENGTH_SHORT).show();
Looper.loop();// 进入loop中的循环,查看消息队列
//2.添加这里,
return false;
}
//3.一定得返回,不然后面会下标越界,估计返回true,一直检查的话,马上就会有真实情况
return true;
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
我也碰到过类似的这种问题,之前的做法是保存usageStats.get(0),因为在某些rom上,长时间停留的话,获取到的usageStats是空List,这个时候我们只需要取上一次保存的usageStats.get(0)即可,然后在进行判断。 |
上一次?时间怎么控制 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我这样改了下就好了。
原:
/*
if (usageStats == null || usageStats.size() == 0) {
if (HavaPermissionForTest(context) == false) {
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
Toast.makeText(context, "权限不够\n请打开手机设置,点击安全-高级,在有权查看使用情况的应用中,为这个App打上勾", Toast.LENGTH_SHORT).show();
}
//发现造成这里的false 是因为 usageStats.size() == 0,即空集合(实际手机有任务存在)
// boolean r = (usageStats == null);
//android.util.Log.e("Current","usageStats:null:"+r);
改后:
//改一下上面的
if (usageStats == null || usageStats.size() == 0) {
if (HavaPermissionForTest(context) == false) {
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
The text was updated successfully, but these errors were encountered: