2015-01-16 194 views
1

我想從啓動程序隱藏我的Android應用程序,但能夠從另一個應用程序中調用它。我迷失在從Android清單中刪除的內容。如何從啓動程序隱藏Android應用程序

已經嘗試刪除...

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

...但隨後從其他應用程序調用時它不會打開。

下面是如何我調用這個隱藏

 Intent i; 
      PackageManager manager = getPackageManager(); 
      try { 
       i = manager.getLaunchIntentForPackage("org.xbmc.xbmc"); 
       if (i == null) 
        throw new PackageManager.NameNotFoundException(); 
       i.addCategory(Intent.CATEGORY_LAUNCHER); 
       startActivity(i); 

      } catch (PackageManager.NameNotFoundException e) { 

這裏是清單

xmlns:android="http://schemas.android.com/apk/res/android"> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="android.permission.GET_TASKS" /> 
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:hasCode="true" android:debuggable="true"> 
    <activity android:theme="@*android:style/Theme.NoTitleBar.Fullscreen" android:name=".Splash" android:finishOnTaskLaunch="true" android:launchMode="singleInstance" android:screenOrientation="sensorLandscape" android:configChanges="touchscreen|keyboard|keyboardHidden|navigation|orientation"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter>     

回答

5

您需要從AndroidManifest.xml刪除以下行:

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

這將刪除從默認啓動的應用程序。但是,您還需要添加以下行,使得您的BroadcastReceiver沒有完全忽視:

<category android:name="android.intent.category.DEFAULT"/> 

不應刪除線下 - 它是用來指定應用程序打開時Activity應首先啓動:

<action android:name="android.intent.action.MAIN"/> 

編輯

爲了啓動從另一個應用程序上面討論的應用程序,你不能使用你的問題顯示的來電。您正在嘗試通過與CATEGORY_LAUNCHER標籤(i.addCategory(Intent.CATEGORY_LAUNCHER))創建一個Intent打開應用程序時,您已顯式刪除以下行從您的AndroidManifest.xml文件:

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

缺少上述線意味着應用程序你試圖打電話會忽略發射Intent。爲了啓動你的應用程序,你將需要採取另一個Intent。這裏展示瞭如何打開一個應用程序,它不包含啓動意圖過濾器,通過響應SMS Intent一個例子:How to launch an Android app without "android.intent.category.LAUNCHER"

你選擇哪一個意圖使用是由你 - 只要確保你添加它到你的AndroidManifest.xml文件。

+0

沒有工作,應用程序不能從其他應用程序打開 – cre8ful

+0

你能發佈你的整個'AndroidManifest.xml'文件嗎?另外,你如何從你的其他應用程序打開這個應用程序? – Willis

+0

加我原來的帖子^^^ – cre8ful

0

的頂部試試這個代碼:

PackageManager p = getPackageManager(); 
    p.setComponentEnabledSetting(getComponentName(), 
     PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 
     PackageManager.DONT_KILL_APP); 

,並檢查該link

希望這有助於。

+1

你知道在哪裏添加嗎?我是新來的... – cre8ful

相關問題