class CheckRunningActivity extends Thread{
ActivityManager am = null;
Context context = null;
public CheckRunningActivity(Context con){
context = con;
am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
}
public void run(){
Looper.prepare();
while(true){
// Return a list of the tasks that are currently running,
// with the most recent being first and older ones after in order.
// Taken 1 inside getRunningTasks method means want to take only
// top activity from stack and forgot the olders.
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
String currentRunningActivityName = taskInfo.get(0).topActivity.getClassName();
if (currentRunningActivityName.equals("PACKAGE_NAME.ACTIVITY_NAME")) {
// show your activity here on top of PACKAGE_NAME.ACTIVITY_NAME
}
}
Looper.loop();
}
}
你可以得到当前运行Activity
,并检查该Activity
相当于Email
应用。
运行CheckRunningActivity
Thread
在Application
启动(或在设备启动时)。
new CheckRunningActivity().start();
更新: 这个类需要android.permission.GET_TASKS
权限,这样在下一行添加到清单:
<uses-permission android:name="android.permission.GET_TASKS" />
@lan如何ü解决您的问题u能请分享你的知识 – nida 2015-01-16 05:11:34
喜有,你得到了解决? – ask4solutions 2016-02-24 06:26:09
我不知道他们是怎么做到的,但像[应用程序保护](http://www.androlib.com/android.application.com-carrotapp-protectdemo12-nFzA.aspx)的应用程序究竟是干什么的你”重新征求意见,所以这确实在技术上是可行的。 – hanspeide 2010-07-20 19:23:22