参考 http://www.2cto.com/kf/201206/137225.html

从Android4.4开始,app可以自定义status bar 背景。 对于一些第三方app定义的状态栏背景,可以在系统源码中对其修改。

SystemUI是随着SystemUIService启动的,SystemUIService是常驻内存的,所以可以增加实时监听/观察功能。

PhoneStatusBar.java中

import android.app.IActivityManager;
import android.app.ActivityManagerNative;
import android.app.IActivityController; IActivityManager mAm; @Override
public void start() {
……
……
mAm = ActivityManagerNative.getDefault();
try {
mAm.setActivityController(new ActivityController());
} catch (RemoteException e) {
} } private class ActivityController extends IActivityController.Stub {
private boolean needUpdate = false;
public boolean activityStarting(Intent intent, String pkg) {
Log.d("antoon", "activityStarting, --> "+pkg);
if("com.android.mms".equals(pkg)){
mBgHandler.sendEmptyMessage(updateBg);
needUpdate = true;
}else if(needUpdate){
mBgHandler.sendEmptyMessage(rebackBg);
needUpdate = false;
}
return true;
} public boolean activityResuming(String pkg) {
Log.d("antoon", "activityResuming, --> "+pkg);
return true;
} public boolean appCrashed(String processName, int pid,
String shortMsg, String longMsg,
long timeMillis, String stackTrace) {
return false;
} public int appEarlyNotResponding(String processName, int pid, String annotation){
return 0;
} public int appNotResponding(String processName, int pid, String processStats) {
return 0;
} public int systemNotResponding(String msg){
return -1;
}
} private final int updateBg = 1;
private final int rebackBg = 2; private Handler mBgHandler = new Handler(){
public void handleMessage(Message msg) {
Log.d("antoon", "mBgHandler, ---, msg = "+msg);
switch (msg.what){
case updateBg:
mStatusBarView.setBackgroundColor(Color.BLUE);
break;
case rebackBg:
mStatusBarView.setBackgroundColor(R.color.system_bar_background_opaque);
break;
}
}
};

android\frameworks\base\core\java\android\app\IActivityController.aidl

/*
**
** Copyright 2009, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/ package android.app; import android.content.Intent; /**
* Testing interface to monitor what is happening in the activity manager
* while tests are running. Not for normal application development.
* {@hide}
*/
interface IActivityController
{
/**
* The system is trying to start an activity. Return true to allow
* it to be started as normal, or false to cancel/reject this activity.
*/
boolean activityStarting(in Intent intent, String pkg); /**
* The system is trying to return to an activity. Return true to allow
* it to be resumed as normal, or false to cancel/reject this activity.
*/
boolean activityResuming(String pkg); /**
* An application process has crashed (in Java). Return true for the
* normal error recovery (app crash dialog) to occur, false to kill
* it immediately.
*/
boolean appCrashed(String processName, int pid,
String shortMsg, String longMsg,
long timeMillis, String stackTrace); /**
* Early call as soon as an ANR is detected.
*/
int appEarlyNotResponding(String processName, int pid, String annotation); /**
* An application process is not responding. Return 0 to show the "app
* not responding" dialog, 1 to continue waiting, or -1 to kill it
* immediately.
*/
int appNotResponding(String processName, int pid, String processStats); /**
* The system process watchdog has detected that the system seems to be
* hung. Return 1 to continue waiting, or -1 to let it continue with its
* normal kill.
*/
int systemNotResponding(String msg);
}

SystemUI中监听app启动,修改app中的状态栏背景色的更多相关文章

  1. wemall app商城源码Fragment中监听onKey事件

    wemall-mobile是基于WeMall的android app商城,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可定制修改.本文分享android开发Fragment中监听onK ...

  2. Windows平台下Oracle监听服务启动过程中日志输出

    Windows平台下Oracle监听服务启动过程中日志输出记录. 日志目录:D:\app\Administrator\diag\tnslsnr\WIN-RU03CB21QGA\listener\tra ...

  3. win10家庭版 监听无法启动 报TNS-12560 TNS-00530

    首先win10权限问题, 搜索设置->更新和安全 ->恢复->高级启动立即重启 疑难解答-高级选项-启动设置-重启-选择“4” 按“WIN+R”组合键,输入“control user ...

  4. 在Activity,Service,Window中监听Home键和返回键的一些思考,如何把事件传递出来的做法!

    在Activity,Service,Window中监听Home键和返回键的一些思考,如何把事件传递出来的做法! 其实像按键的监听,我相信很多人都很熟练了,我肯定也不会说这些基础的东西,所以,前期,还是 ...

  5. Oracle监听已经启动了 sqlplus / as sysdba 仍然报 ERROR:ORA-12560

    我的Oracle是11g的 system 的密码忘记了, 但是scott的密码我还记得而且能登录 . 想以sqlplus /as sysdba 修改system密码 一直在报 ERROR:ORA-12 ...

  6. Android-服务中监听电源键和Home键的广播、在锁屏下仍然工作的方法

    Android-服务中监听电源键和Home键的广播  http://blog.csdn.net/u014657752/article/details/49512485 Android开发之如何监听让服 ...

  7. Fragment中监听onKey事件,没你想象的那么难。

    项目中越来越多的用到Fragment,在用Fragment取代TabHost的时候遇到了一个问题,我们都知道,TabHost的Tab为Activity实例,有OnKey事件,但是Fragment中没有 ...

  8. hosts文件权限导致监听无法启动

    1.所属系统:2.问题描述:3.解决4.参考???疑点:为什么修改主机名会使hosts文件权限发生改变 1.所属系统: ZHJS2#[/]uname -a HP-UX ZHJS2 B.11.31 U ...

  9. linux下oracle数据库服务和监听的启动停止

    oracle数据库是重量级的,其管理非常复杂,将其在linux平台上的启动和关闭步骤整理一下. 安装完毕oracle以后,需要创建oracle系统用户,并在/home/oracle下面的.bash_p ...

  10. Vue 为什么在 HTML 中监听事件?

    为什么在 HTML 中监听事件? 你可能注意到这种事件监听的方式违背了关注点分离(separation of concern)传统理念.不必担心,因为所有的 Vue.js 事件处理方法和表达式都严格绑 ...

随机推荐

  1. TCP协议-连接建立和释放

    三次握手: (1)客户端向服务器端TCP请求连接,向服务器端发送控制位SYN=1,序号seq=x的请求报文.(x是随机产生的,且不能为0) (2)服务器端接收到请求报文后,若同意建立连接,则向客户端发 ...

  2. Python学习日记 --day4

    list列表: # # 列表 ''' # 增 # li = [1,'qwer','小明',[1,2,'qwe']] # print(li[0],type(li)) # 跟字符串的操作方法是一样的,返回 ...

  3. linux centos 磁盘清理

    执行df -h 与 du -sh / 所查询到的已用容量不对应 执行xfs_fsr来清理磁盘 参考 https://www.jianshu.com/p/0ded68808123

  4. Git自学笔记

    Git是什么? Git是目前世界上最先进的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git与SVN的区别有哪些? ① Git是分布式的,SVN不是.这是Git和其它非分布式版本控制系 ...

  5. error: undefined reference to 'android::hardware::details::return_status::~return_status()'

    use hidl , make fail. reason is:missing libs:libbinder

  6. 爬了招聘网站之后,总结Python学习的几点建议

    来源商业新知网,原标题::爬了招聘网站之后,给你几点学习Python的建议 Python语言相关的岗位非常多,有运维,有自动化测试,有后端开发,有机器学习,如果想要快速上手,并且有不错的就业,那就推荐 ...

  7. SQL函数总结

    字符串函数

  8. tensorflow 升级到1.9-rc0,tensorboard 报错:TypeError: GetNext() takes exactly 1 argument (2 given)

    Exception in thread Reloader:Traceback (most recent call last):  File "/usr/lib/python2.7/threa ...

  9. phpstudy打开网页很慢如何处理

    目录下,.env 配置数据库连接改为DB_HOST=127.0.0.1

  10. mybatisplus打印sql语句

    package com.osplat.config; import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; ...