2013-04-14 31 views
-1

我想殺死短信應用程序,當它打開。爲此我寫了一項服務。它檢查是否打開短信應用程序。如果是的話就殺死它。我正在使用ActivityManager類。這裏是我的代碼 ,但是當我啓動短消息應用程序時,ne nevers結束。爲什麼?可能嗎 ?如果是的話,請幫助。查殺其他應用程序

package com.example.activitymanager; 

import java.util.List; 

import android.app.ActivityManager; 
import android.app.IntentService; 
import android.content.Intent; 
import android.os.Handler; 
import android.util.Log; 

public class Servicee extends IntentService { 
    ActivityManager am; 
    Handler handler = new Handler(); 
    Runnable r = new Runnable() { 

     @Override 
     public void run() { 
      List<ActivityManager.RunningTaskInfo> list = am 
        .getRunningTasks(Integer.MAX_VALUE); 
      for (ActivityManager.RunningTaskInfo task : list) { 
       if (task.baseActivity.getPackageName() 
         .equals("com.android.mms")) { 
        am.restartPackage(task.baseActivity.getPackageName()); 
       } 
      } 
      handler.postDelayed(this, 5000); 
     } 
    }; 

    public Servicee() { 
     super(""); 
    } 

    @Override 
    protected void onHandleIntent(Intent arg0) { 
     am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); 
     handler.postDelayed(r, 2000); 

    } 

} 
+0

我寫過一次[某些應用程序無法被殺](http://stackoverflow.com/questions/15744928/how-to-force-stop-all-checked-application-from-list-view- in-android-programmatic#comment22373283_15744928),除此之外,你如何解決殺死應用程序的意圖? – WarrenFaith

+0

使用服務,並獲得進程id和amd殺死進程 –

回答

0

我同意Usman Riaz的評論,但請記住,進程ID可能因設備而異。我想監視特定應用程序的tpc流量,並且id最終沒有發揮作用。你會殺了一些其他的應用程序或崩潰的系統。

+0

通過使用'ActivityManager'我可以得到正在運行的prosecc id通過它的包名識別它。但你是對的,我試圖殺死短信應用程序的步驟,但殺了它之後,再次出現與不同的編號 –

+0

是的,也是Android試圖保持一些應用程序存活 – Goot

+0

我想阻止用戶發送短信,是否有可能?有很多應用程序也是這樣做的。 –

相關問題