Android:如何控制主页按钮

发布于 2024-11-26 04:56:34 字数 776 浏览 1 评论 0原文

我们正在尝试为我邻居的精神和身体残疾的女儿提供一个应用程序,让她使用 Android 平板电脑作为说话者,即她按下几个大按钮,设备就会生成语音。该应用程序基本上是一个 WebView 和一个 Javascript 中的附加对象,用于执行和控制语音生成,以及一些处理方向更改的逻辑。 Html 文件是根据谈话项目的特定布局离线生成的。我们还添加了一些音乐播放和图片查看功能,以使该设备对她更具吸引力。

问题是,主页按钮让她回到了 Android 启动器屏幕的疯狂状态,并且在测试设备(Archos 70)上,主页按钮不是物理按钮,而是显示在触摸屏本身上,因此很容易不小心撞到了。

因此,我只想通过按顺序按“主页”、“返回”、“主页”来返回 Android 启动器,中间没有其他操作。

我可以通过让我的应用程序本身成为启动器来实现此目的吗?然后,我如何才能按照“主页”、“返回”、“主页”顺序返回到原始启动器?看来这已经深入Android的内部了,是吧?

到目前为止我发现的唯一线索是 覆盖主页用于 Car Home 替换应用程序的按钮,但该按钮的评级为 -1,并且据报道只能在模拟器中使用。另外,我怀疑我是否可以完全放弃原来的启动器,否则就无法再访问 USB 海量设备控件,以允许下载新的 HTML 文件、终止和重新启动应用程序等。

我也愿意去拼凑。也许可以启动后台服务,根据需要再次将应用程序带到前台?

We're trying to provide an application to the mentally and physically handicapped daughter of my neighbor that let's her use an Android tablet as a Talker, i.e., she presses a few big buttons and the devices generates speech. The application is basically a WebView and an additional object in Javascript used to perform and control the speech generation, plus some logic to handle the orientation changes. Html files are generated offline for her specific layout of the talking items. We've also added some music playing and picture viewing facilities to make the device more appealing to her.

Problem is that the home button brings her back into the madness of the Android launcher screen, and that on the test device (Archos 70) the home button is not a physical button but rather shown on the touch screen itself, making it too easy to accidentally hit it.

So I'd like to return to the Android launcher only by pressing a sequence home, back, home with no other action in between.

Can I achieve this by making my application itself the launcher? How can I then get back to the original launcher upon the home, back, home sequence? It seems that this goes deep into the innards of Android, huh?

The only clue I found so far is Overriding Home button for a Car Home replacement app, but this is rated -1 and reported to work in the emulator only. Also I doubt if I could completely abandon the original launcher, as otherwise there is no access anymore to e.g. the USB mass device control to allow new HTML files to be downloaded, the application to be killed and restarted, and so forth.

I'm willing to go for a kludge as well. Maybe a background service could be started that would bring the application to the front again as necessary?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鸩远一方 2024-12-03 04:56:34

主页按钮无法被覆盖。您可以编写一个响应主页意图的应用程序(这就是启动器的作用),但仅此而已。

The Home button cannot be overriden. You can write an application that responds to the home intent (that's what a launcher does) but that's all.

七婞 2024-12-03 04:56:34

我可以通过让我的应用程序本身成为启动器来实现此目的吗?然后,我如何才能按照“主页”、“返回”、“主页”顺序返回到原始启动器?看来这已经深入Android的内部了,是吧?

是的。不太深入
内脏。您可以通过指定组件来手动启动启动器,请注意,这可能因设备和用户而异,如果您只是私下使用它,您可以对其进行硬编码,但如果您发布它,则必须允许用户指定他们真正的家庭应用程序。

/* This should come from a preference that let's the user select an activity that can handle the HOME intent */
String packageName = "com.android.launcher";
String packageClass = "com.android.launcher2.Launcher";

Intent home_intent = new Intent(Intent.ACTION_MAIN);
home_intent.addCategory(Intent.CATEGORY_HOME);
home_intent.setComponent(new ComponentName(packageName, packageClass));
home_intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
/* Here you should catch the exception when the launcher has been uninstalled, and let the user save themselves by opening the Market or an app list or something. Users sometimes use root apps to uninstall the system launcher, so your fake launcher is all that is left. Might as well give the poor user a hand. */
startActivity(home_intent);

检测 home/back/home 有点尴尬,因为 home 不会作为 onKeyEvent 出现,而​​是作为新意图出现。只需长按后退按钮然后显示提示可能是一种安全/好的方法。

Can I achieve this by making my application itself the launcher? How can I then get back to the original launcher upon the home, back, home sequence? It seems that this goes deep into the innards of Android, huh?

Yes. Not too deep into the
innards. You can manually start a launcher by specifying the component, note that this may vary from device to device and user to user, if you're just using this privately you could hard code it, but if you release it you must allow the user to specify their real home app.

/* This should come from a preference that let's the user select an activity that can handle the HOME intent */
String packageName = "com.android.launcher";
String packageClass = "com.android.launcher2.Launcher";

Intent home_intent = new Intent(Intent.ACTION_MAIN);
home_intent.addCategory(Intent.CATEGORY_HOME);
home_intent.setComponent(new ComponentName(packageName, packageClass));
home_intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
/* Here you should catch the exception when the launcher has been uninstalled, and let the user save themselves by opening the Market or an app list or something. Users sometimes use root apps to uninstall the system launcher, so your fake launcher is all that is left. Might as well give the poor user a hand. */
startActivity(home_intent);

Detecting home/back/home is a bit awkard because home won't come as a onKeyEvent but instead as a new intent. Simply long-pressing the back button then display a prompt is probably a safe/good approach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文