问题描述
我想在启动器中隐藏我的android应用程序,但可以从另一个应用程序中调用它.我迷失了要从android清单中删除的内容.
I would like to hide my android app from the launcher, but be able to call it from within another app. I am lost on what to remove from the android manifest.
已经尝试删除...
<意图过滤器>< action android:name ="android.intent.action.MAIN"/>< category android:name ="android.intent.category.LAUNCHER"/></intent-filter>
...但是当从另一个应用程序调用时,它不会打开.
...but then it doesn't open when called from another app.
这就是我怎么称呼这个隐藏的
Here is what how I am calling this hidden
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>
推荐答案
您需要从 AndroidManifest.xml
中删除以下行:
You need to remove the following line from your AndroidManifest.xml
:
<category android:name="android.intent.category.LAUNCHER"/>
这将从默认启动器中删除该应用程序.但是,您还需要添加以下行,以使您的 BroadcastReceiver
不会被完全忽略:
This will remove the application from the default launcher. However, you also need to add the following line such that your BroadcastReceiver
is not completely ignored:
<category android:name="android.intent.category.DEFAULT"/>
您不应删除下面的行-它用于指定打开应用程序时应先启动哪个 Activity
:
You should NOT remove the line below - it is used to specify which Activity
should launch first when your app is opened:
<action android:name="android.intent.action.MAIN"/>
编辑
为了从另一个应用程序启动上面讨论的应用程序,您不能使用问题中显示的调用.您试图通过显式创建带有 CATEGORY_LAUNCHER
标签( i.addCategory(Intent.CATEGORY_LAUNCHER)
)的 Intent
来打开应用程序从 AndroidManifest.xml
文件中删除了以下行:
In order to launch the application discussed above from another application, you cannot use the calls shown in your question. You are trying to open the application by creating an Intent
with the CATEGORY_LAUNCHER
tag (i.addCategory(Intent.CATEGORY_LAUNCHER)
) when you have explicitly removed the following line from your AndroidManifest.xml
file:
<类别android:name ="android.intent.category.LAUNCHER"/>
缺少上述行意味着您尝试调用的应用程序将忽略启动 Intent
.为了启动您的应用程序,您将需要对另一个 Intent
进行操作.以下示例显示了如何通过响应SMS Intent
来打开不包含启动意图过滤器的应用程序:
The absence of the above line means that the application you are trying to call will ignore the launch Intent
. In order to launch your application you will need to act upon another Intent
. Here is an example that shows how to open an application, which doesn't contain a launch intent filter, by responding to a SMS Intent
: How to launch an Android app without "android.intent.category.LAUNCHER"
您选择使用哪种意图完全取决于您-只需确保将其添加到您的 AndroidManifest.xml
文件中即可.
Which intent you choose to use is up to you - just make sure you add it to your AndroidManifest.xml
file.
这篇关于如何从启动器隐藏android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!