Android的:如何控制home键 [英] Android: How to control the home button

查看:174
本文介绍了Android的:如何控制home键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在努力提供应用程序的精神和身体残疾的女儿我的邻居,它可以让她使用Android平板电脑作为一个健谈,也就是她presses几大按钮和设备产生的讲话。应用程序基本上是一个web视图和用于执行和控制语音代在Javascript的另一个目的,再加上一些逻辑来处理的取向的变化。 HTML文件脱机她的具体的讲项目布局产生。我们还增加了一些音乐播放和图片浏览设施,使设备更吸引她。

问题是,home键带她回了Android发射画面的疯狂,以及测试设备(爱可视70)上的主页按钮不是一个物理按钮,但触摸屏本身上,而显示,使之太容易不小心碰到它。

所以我想只能由$ P $返回到Android发射pssing序列回家,回来了,在家中的任何其他操作。

我可以通过我的应用程序本身的启动实现这一目标?我怎样才能再回到原来的发射后的主页,返回,家序列?看来,这个深入到机器人的内部结构,是吧?

我发现迄今唯一的线索是<一个href="http://stackoverflow.com/questions/2862629/overriding-home-button-for-a-car-home-replacement-app/4538477#4538477">Overriding主页按钮用于车载主替换应用,但这是在额定-1和报告只仿真器工作。此外,我怀疑我是否能完全抛弃原来的发射,否则就没有再进入到如USB大容量设备的控制,以允许新的HTML文件被下载,应用程序被杀死并重新启动,等等。

我愿意去一个杂牌组装电脑也是如此。也许一个后台服务可以被启动,将带来应用到前台再次必要?

解决方案
  

我可以通过我的应用程序本身的启动实现这一目标?我怎样才能再回到原来的发射后的主页,返回,家序列?看来,这个深入到机器人的内部结构,是吧?

是的。不要太深进 内脏。您可以通过指定的组件手动启动了启动程序,注意,这可能会有所不同,从设备到设备和用户到用户,如果你仅仅使用这家私人你可以硬code,但如果你释放它,你必须允许用户可以指定自己的真正的家应用程序。

  / *这应该是从我们的用户选择,可以处理HOME意图活性的preference * /
字符串的packageName =com.android.launcher;
字符串packageClass =com.android.launcher2.Launcher;

意图home_intent =新的意图(Intent.ACTION_MAIN);
home_intent.addCategory(Intent.CATEGORY_HOME);
home_intent.setComponent(新的组件名(的packageName,packageClass));
home_intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
/ *在这里,您应该捕获异常时,发射器已被卸载,并让用户保存自己打开市场或应用程序列表或什么的。用户有时会使用根应用程序卸载系统​​启动,因此你的假发射器是所有剩下的。还不如给穷人用户的手。 * /
startActivity(home_intent);
 

检测回家/回/ home是一个有点awkard,因为家里不会来作为onKeyEvent而是作为一个新的意图。只要长期pressing返回按钮,然后显示一个提示,可能是一个安全/好方法。

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?

解决方案

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.

这篇关于Android的:如何控制home键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆