2011-05-12 42 views
0

我正在編寫一個android應用程序,它在後臺將監視device.I希望得到一個指示,每當一個應用程序移動到background/foreground.Also我想得到一個指示時安裝或從android設備上卸載的應用程序。 這怎麼可能在Android?請help.thank你指示當ap移動到背景,當安裝包時

回答

0

對於您的問題的前景/背景部分看看"Activity Lifecycle"

有關安裝的通知和卸載你可以註冊移動到這個問題的背景/前景部分的事件Intent.ACTION_PACKAGE_ADDEDIntent.ACTION_PACKAGE_REMOVED

喜歡的東西

registerReceiver(new BroadcastReceiver() { 

    public void onReceive(Context context, Intent intent) { 
     // do something 
    } 

}, new IntentFilter(Intent.ACTION_PACKAGE_ADDED)); 
+0

您好Juri,我不感興趣在我的活動回到/爲...我想知道什麼時候其他應用程序的狀態改變。 – Kozlov 2011-05-19 11:07:27

2

爲App一個BroadcastReceiver:據我所知有除了你自己的應用程序是沒有辦法做到這一點,這是我認爲你在這裏想要的。

對於安裝/卸載檢測,你需要在你的應用程序註冊一個BroadcastReceiver接收ACTION_PACKAGE_ADDED & ACTION_PACKAGE_REMOVED意圖。就像:

BroadcastReceiver br = new BroadcastReceiver() {    
    @Override 
    public void onReceive(Context context, Intent intent) { 
     // Your implementation     
    } 
}; 

registerReceiver(br, new IntentFilter(Intent.ACTION_PACKAGE_ADDED)); 
registerReceiver(br, new IntentFilter(Intent.ACTION_PACKAGE_REMOVED)); 
+0

對於應用程序移動到後臺/前臺,它看起來像你是正確的。但是我堅持使用我的應用程序:(。感謝您的信息 – Kozlov 2011-05-19 11:06:37

+1

很高興爲您提供幫助。如果您覺得它已完成,請將此問題標記爲已回答。 – 2011-05-19 19:37:57