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