2013-01-07 119 views
19

我在寫一個(合法)間諜程序。我想讓這個程序隱藏在啓動器上(所以沒有圖標顯示)。我試圖從AndroidManifest.xml中刪除<category android:name="android.intent.category.LAUNCHER" />行,但是然後用戶無法以第一啓動模式(配置)啓動應用程序。誰有什麼想法?Android隱藏應用程序

我該怎麼辦呢?

回答

31

您需要將您的應用程序變爲服務。這裏是機器人會採取創建服務組件:

http://developer.android.com/guide/components/services.html

上MobiWare發現這個問題,以及:

當你想跟蹤移動的使用或收集一些數據,在用戶不知情,這可能幫助您。

第1步:創建一個沒有圖標的應用程序。 通常,活動在清單中聲明如下。

 <activity 
     android:label="@string/app_name" 
     android:name="org.security.tracker.Tracker-activity" > 
     <intent-filter > 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

刪除類別標籤,你不會得到應用程序圖標了。 現在,你不再需要活動了。所以刪除這個部分。 你可能會想,該應用如何在沒有任何觸發的情況下運行,或者應用的起點是什麼。 這是解決方案。

<!-- Start the Service if applicable on boot --> 
    <receiver android:name="org.security.tracker.ServiceStarter" > 
     <intent-filter > 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     </intent-filter> 
    </receiver> 

這會觸發您在那裏寫的Receiver中的代碼,您可以運行服務來實現您的想法。

<service android:name="org.security.tracker.serviceCode" /> 

您需要添加此權限,

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

你的代碼的時候,手機只能重新啓動運行。

步驟2.編寫代碼

在重新啓動時,recevier會火,有你就可以開始你的服務。

class ServiceStarter extends BroadcastReceiver { 

@Override 
public void onReceive(Context _context, Intent _intent) { 

    Intent i = new Intent("com.prac.test.MyPersistingService"); 
    i.setClass(_context, ServiceCode.class); 
    _context.startService(i); 
    } 

} 
+6

的Android工作室將無法編譯,如果有在androidmanifest – Plugie

+0

沒有啓動程序類別如何服務代碼將會執行,如果你不能啓動應用程序,Android studio將不會第一次編譯 – abh22ishek

+0

直到我開始活動一次,纔在BroadcastReceiver中接收到任何呼叫 –

3

從清單文件

+0

@AmitApollo,無需創建服務。 – xoq

+5

應用程序將如何啓動? – Squonk

+2

@Squonk我不是專家,但也許它是一個廣播接收器? –

0

刪除

<intent-filter > 
<action android:name="android.intent.action.MAIN" /> 
<category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter> 

您可以從AndroidManifest.xml文件刪除<category android:name="android.intent.category.LAUNCHER"/>

但記得要加<category android:name="android.intent.category.LEANBACK_LAUNCHER"/>,使Android的工作室將能夠編寫你的應用程序(從啓動又隱藏):):d