如何制作启动器
我已经开发了相当长的一段时间,现在我正在尝试制作一个应用程序来取代原来的主页(例如HTC sense)。
我需要当用户点击手机上的主页按钮时打开该应用程序。
所以基本上它是一个家庭的替代品。
有人知道该怎么做吗?
I have been developing for quite a time and I am now trying to make an app that will replace the original home (e.g. HTC sense).
I need the app to open when the the user hits the home button on their phone.
So basically it is a home replacement.
Does any one know how to go about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需开发一个普通的应用程序,然后在应用程序的清单文件中添加几行即可。
首先,您需要将以下属性添加到您的活动中:
然后将两个类别添加到意图过滤器中:
结果可能如下所示:
就这么简单!
Just develop a normal app and then add a couple of lines to the app's manifest file.
First you need to add the following attribute to your activity:
Then add two categories to the intent filter :
The result could look something like this:
It's that simple!
它们是 Android 团队提供的示例,如果您已经加载了示例,则可以按照以下步骤导入主屏幕替换示例。
但是如果您没有加载示例,请使用以下步骤下载它
They're examples provided by the Android team, if you've already loaded Samples, you can import Home screen replacement sample by following these steps.
But if you do not have samples loaded, then download it using the below steps
我不久前在创建自己的启动器之前看到了这个帖子。
以下是我学到的一些重要知识:
将您的应用程序声明为启动器
David 已经提到了将您的应用程序确定为启动器的代码段:
将其添加为
intent-filter
到您的启动器将用于主屏幕的 Activity (在AndroidManifest.xml
)。启动器问题
由于启动器会一直运行,因此您需要了解活动生命周期< /a> 以防止出现问题(像这个)。
如果您希望用户(和您自己)能够持续使用该应用(这就是您通常使用启动器所做的事情),确保它永远不会崩溃。如果发生崩溃,用户将被收回到设备默认启动器或其他已安装的启动器。
简而言之:启动器应该是可靠的。
常见的启动器功能(用户通常期望这些功能)
1) 应用程序/appdrawer 列表
,可以从中启动或修改所有应用程序。您可以使用
packageManager
列出应用程序。由于生成这样的列表可能需要一段时间,我建议您异步执行并将列表保存在某个地方以加快一切速度(这也是启动器所期望的^^)
2)一些更改启动器的设置
在实现这些之前,我有一些用户卡在了我的启动器中 ^^
您可以像这样打开设备启动器设置(在 Kotlin 中):
奖励)应用内教程
如果您的应用程序中有一些不具备的功能,这可能会很有用琐碎、方法启动用户不知道其他应用程序的应用程序。
它还可以减少用户询问如何与您的软件交互的消息。
资源:
I saw this thread a while ago, before creating my own launcher.
Here are some crucial things I learned:
Declaring your app to be a launcher
David already mentioned the piece of code that determines your app as a launcher:
Add this as an
intent-filter
to the activity your launcher will use for the home screen (inAndroidManifest.xml
).Launcher Issues
As a launcher will run all the time, you need to understand the activity livecycle to prevent issues (like this one).
If you want users (and yourself) to be able to constantly user the app (that's what you usually do with launchers), make sure it never crashes. In the case of a crash users will be taken back to the devices default launcher or other installed ones.
In short: Launchers are expected to be reliable.
Common launcher functions (users usually expect those)
1) A list of apps / appdrawer
From which all apps can be launched or modified. You can use
packageManager
to list the apps.As generating such a list may take a while, I suggest you to do it asynchronously and save the list somewhere to speed everything up (which also is expected from launchers ^^)
2) Some settings to change the launcher
I had some users stuck in my launcher before implementing those ^^
You can open the devices launcher settings like this (in Kotlin):
Bonus) An in-app tutorial
This may be useful if you have some features in your app that are not trivial, ways of launching apps that users don't know from other apps.
It also gets you way less messages from users asking how to interact with your software.
Resources:
好吧,首先你需要听
android.intent.category .HOME
意图。以下是一些包含完整源代码的链接,您可以查看:或者查看<一个href="http://code.google.com/p/android-launcher-plus/" rel="noreferrer">启动器 plus。
Well, firstly you need to listen to the
android.intent.category.HOME
intent. Here are some links with full source code which you can have a look at:Or take a look at launcher plus.