Android ActivityManager与WindowManager
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- 使用SYSTEM_ALERT_WINDOW时必须要加 -->
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.TextView;
public class MainActivity extends Activity {
private ActivityManager mActivityManager;
private Handler popupHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
String packageName = mActivityManager.getRunningTasks(1).get(0).topActivity.getPackageName();
Log.e("log", packageName + System.currentTimeMillis());
if (packageName.equals("com.some.app.name")) {
popupHandler.sendEmptyMessage(1);
}
if (isRunning) {
popupHandler.sendEmptyMessageDelayed(0, 3500);
}
break;
case 1:
Log.e("log", "mWindowManager");
if (!isAdd) {
startActivity(new Intent(MainActivity.this, MainActivity.class));
mWindowManager.addView(mTrackingText, lp);
isAdd = true;
}
break;
}
}
};
WindowManager mWindowManager;
private boolean isRunning = true;
WindowManager.LayoutParams lp;
TextView mTrackingText;
boolean isAdd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
mTrackingText = new TextView(MainActivity.this);
mTrackingText.setTextColor(Color.BLUE);
mTrackingText.setTextSize(55);
mTrackingText.setText("00:00");
lp = new WindowManager.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
isRunning = true;
popupHandler.sendEmptyMessageDelayed(0, 3500);
}
}
Android ActivityManager与WindowManager的更多相关文章
- Android ActivityManager.killBackgroundProcesses方法去结束
android2.2以后,如果服务在ondestroy里加上了start自己,用kill backgroudprocess通常无法结束自己.有一种最新发现的方法,利用反射调用forceStopPack ...
- Delphi Android ActivityManager(提供了接口, 利用它可以方便的对Memory, Processes, Task, Service 等进行管)
ActivityManager: 对Activity交互提供了接口, 利用它可以方便的对Memory, Processes, Task, Service 等进行管理,. 这里对Delphi接口进行 ...
- Android 悬浮窗 WindowManager WindowManager.LayoutParamas
前方高清大图~~~~ 绘制的图片资源: // draw bitmap BitmapDrawable bmpDraw = (BitmapDrawable) getResources().getDrawa ...
- 图解Android - Zygote, System Server 启动分析
Init 是所有Linux程序的起点,而Zygote于Android,正如它的英文意思,是所有java程序的'孵化池'(玩过星际虫族的兄弟都晓得的).用ps 输出可以看到 >adb shell ...
- 设计模式-结合Android代码
开始学设计模式 1 单例模式 单例模式可以说是最容易理解的模式了,也是应用最广的模式之一,先看看定义吧. 定义:确保单例类只有一个实例,并且这个单例类提供一个函数接口让其他类获取到这个唯一的实例. 什 ...
- Android中的IPC机制
Android IPC简介 IPC是Inter-Process Communication的缩写,含义就是进程间通信或者跨进程通信,是指两个进程之间进行数据交换的过程.那么什么是进程,什么是线程,进程 ...
- 《android开发艺术探索》读书笔记(二)--IPC机制
接上篇<android开发艺术探索>读书笔记(一) No1: 在android中使用多进程只有一种方法,那就是给四大组件在AndroidMenifest中指定android:process ...
- Android开发艺术探索——第二章:IPC机制(上)
Android开发艺术探索--第二章:IPC机制(上) 本章主要讲解Android的IPC机制,首先介绍Android中的多进程概念以及多进程开发模式中常见的注意事项,接着介绍Android中的序列化 ...
- android binder机制详解
摘要 Binder是android中一个很重要且很复杂的概念,它在系统的整体运作中发挥着极其重要的作用,不过本文并不打算从深层次分析Binder机制,有两点原因:1是目前网上已经有2篇很好的文章了,2 ...
随机推荐
- DIV背景图片定位问题
<div class="custom-topNavigation_shadow"> </div> 正确写法 .custom-topNavigation_ ...
- 【调研】在总体为n的情况下,多少样本有代表性?
见这里: http://www.raosoft.com/samplesize.html
- varchar和nvarchar的区别 数据来证明
如果一个数据是"N好"数据类型是varchar时: select len(vartest) from testselect datalength(vartest) from tex ...
- Linux下的ssh远程访问
准备工作:首先需要在windows系统中安装虚拟机,并在虚拟机中安装好linux操作系统,这里安装的是vmware player虚拟机和ubuntu版本的操作系统.关于该部分的安装在作者的其他经验中有 ...
- npm 安装碰到SSL问题
经过仔细排查和google,原来是ssl 的问题: 解决办法: npm config set strict-ssl false
- polarssl rsa & aes 加密与解密
上周折腾加密与解密,用了openssl, crypto++, polarssl, cyassl, 说起真的让人很沮丧,只有openssl & polarssl两个库的RSA & AES ...
- Mysql主从热备
mysql主从配置比较不错的文章,大家可以参考下~ https://www.cnblogs.com/kissdodog/p/5422195.html
- hbase shell 启动报错
启动hbase之后,发现hbase shell启动报错: version 2.0.0-alpha4, r5c4b985f89c99cc8b0f8515a4097c811a0848835, Tue Oc ...
- Bypass X-WAF SQL注入防御(多姿势)
0x00 前言 X-WAF是一款适用中.小企业的云WAF系统,让中.小企业也可以非常方便地拥有自己的免费云WAF. 本文从代码出发,一步步理解WAF的工作原理,多姿势进行WAF Bypass. ...
- Explaining Delegates in C# - Part 5 (Asynchronous Callback - Way 2)
In this part of making asynchronous programming with delegates, we will talk about a different way, ...