简体   繁体   English

动态设置默认的家庭应用

[英]Set default Home app dynamically

Can I set dynamically within an activity the preferred/default application that's to be launched when I push the Home key? 我可以在活动中动态设置按下Home键时要启动的首选/默认应用程序吗? If that's not possible, can I at least reset current defaults so that the chooser window re-appears? 如果那不可能,我是否至少可以重置当前默认设置,以便重新显示选择器窗口? I tried to implement the latter by calling PackageManager.clearPackagePreferredActivities("com.android.launcher"), but that doesn't seem to do it(I gave my activity SET_PREFERRED_APPLICATIONS permission). 我试图通过调用PackageManager.clearPackagePreferredActivities(“ com.android.launcher”)来实现后者,但这似乎并没有做到(我向我的活动设置了SET_PREFERRED_APPLICATIONS权限)。

Can I set dynamically within an activity the preferred/default application that's to be launched when I push the Home key? 我可以在活动中动态设置按下Home键时要启动的首选/默认应用程序吗?

No. There is no exposed API for this. 否。没有公开的API。

If that's not possible, can I at least reset current defaults so that the chooser window re-appears? 如果那不可能,我是否至少可以重置当前默认设置,以便重新显示选择器窗口?

Only if you are implementing the home screen that is the current default. 仅当您实现当前默认的主屏幕时。

I tried to implement the latter by calling PackageManager.clearPackagePreferredActivities("com.android.launcher") 我试图通过调用PackageManager.clearPackagePreferredActivities(“ com.android.launcher”)来实现后者

As the documentation for that method states, "An application can only clear its own package(s).". 正如该方法的文档所述,“应用程序只能清除其自己的程序包”。

An application can only clear its own package(s). 应用程序只能清除其自己的程序包。

This can't be true.... the App "Toddler Lock" has figured out a way around this. 事实并非如此。...应用程序“幼儿锁”已经找到解决该问题的方法。 I've tested it as follows: 我已经对其进行了如下测试:

  1. Install Toddler Lock 安装幼儿锁
  2. open Toddler Lock 打开幼儿锁
  3. checked "Set as Default" 选中“设置为默认”
  4. chose other app(not Toddler Lock) as default 选择其他应用(非幼儿锁)作为默认应用
  5. Opened Toddler Lock again 再次打开幼儿锁
  6. Even though I have already chosen another app as default I am again prompted to choose the default which means Toddler Lock has cleared the user defined default of another app 即使我已经选择了另一个应用程序作为默认应用程序,我仍然会再次提示您选择默认设置,这意味着Toddler Lock已清除了用户定义的另一个应用程序的默认设置
  7. Close app and now Toddler Lock removes itself from being default 关闭应用程序,现在“幼儿锁”将自己从默认设置中删除
  8. If more than one "Home" app exist when Toddler Lock closes (first time only) the next time you press "Home" you are prompted to choose a default "Home" app. 如果在下次您按下“主页”时幼儿锁关闭时(仅限第一次),存在多个“主页”应用程序,则会提示您选择默认的“主页”应用程序。 Again this proves the setting can be removed by a third party app 再次证明该设置可以被第三方应用删除

In Android versions prior to 2.2: 在2.2之前的Android版本中:

  1. Install Toddler Lock 安装幼儿锁
  2. Without prompting user Toddler Lock sets itself as default "Home" app and therefore has cleared the setting 在不提示用户的情况下,幼儿锁将其自身设置为默认的“家庭”应用,因此已清除了该设置
  3. Close Toddler Lock and it removes itself as default again no prompting 关闭幼儿锁,它会再次默认删除自身,没有提示

Now maybe something has changed since this post... but as far as I am aware Toddler Lock has been around since at lease API ver 1.5 and has always been able to do this. 现在,自这篇文章发布以来,也许有些事情发生了变化……但是据我所知,Toddler Lock自API版本1.5开始就存在,并且一直能够做到这一点。 Which doesn't bother me because the app provides an awesome functionality but I would like to know how to accomplish this in my app. 这并不打扰我,因为该应用程序提供了很棒的功能,但是我想知道如何在我的应用程序中完成此操作。

NOTE: Security has at least increased as now the user is required to choose the "Default App" the first time through. 注意:由于现在要求用户第一次选择“默认应用程序”,因此安全性至少有所提高。 Even the dev states in his app upon first time use that the new requirement is present since API ver 2.2 甚至开发人员在首次使用应用程序时就声明,自API版本2.2起就存在新要求

I'm saying this can't be nearly as hard as it is being made to sound. 我的意思是说这听起来很难。 I've been working to figure out a way to do this myself. 我一直在努力想办法自己做。 I know this thread is old, but since it's still open, I'll give my answer. 我知道这个线程很旧,但是由于它仍然是打开的,所以我给出答案。

Sadly, I have no idea what I'm doing (not really a programmer), so I've yet to code an original app to do this. 可悲的是,我不知道自己在做什么(不是真正的程序员),所以我还没有编写一个原始应用程序来做到这一点。 Regardless, I've managed to replicate the intended effect with Tasker App Factory, and Home2 Shortcut... Using Target as Home (another mrkt app) would likely achieve a better result than home2, but I've yet to try it. 无论如何,我已经设法使用Tasker App Factory和Home2 Shortcut复制了预期的效果...使用Target as Home(另一个mrkt应用程序)可能会比home2取得更好的结果,但是我还没有尝试过。

Basically, I've just created a shell with the TskrFactory, with a popup that holds all my home launchers as shortcuts (yet to figure out a way to make them user-modifiable on the fly, but should be easy for yall, no?). 基本上,我刚刚用TskrFactory创建了一个shell,并带有一个弹出窗口,该弹出窗口将我所有的家庭启动器都保存为快捷方式(还想出一种使它们在运行时用户可修改的方法,但是应该很容易,不是吗? )。 Basically just a glorified variable/ shortcut... Whichever launcher is selected becomes the %var - once it's cleared, the next home press brings up the prompt again. 基本上只是一个美化的变量/快捷方式...选择了哪个启动器都将成为%var-清除它后,下次按下主屏幕将再次弹出提示。 Technically, it's home2 that is the default home. 从技术上讲,默认位置为home2。 Primitive, I'm sure, but effective nevertheless. 我敢肯定,原始但仍然有效。 A proof of concept, if nothing else. 概念证明,如果没有别的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM