0

Can I set dynamically within an activity the preferred/default application that's to be launched when I push the Home key? 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).

Raj
  • 5
  • 1
  • 3

3 Answers3

5

Can I set dynamically within an activity the preferred/default application that's to be launched when I push the Home key?

No. There is no exposed API for this.

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")

As the documentation for that method states, "An application can only clear its own package(s).".

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

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
  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:

  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. 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

  • did u ever find out how toddler lock achieves this? i also have similar requirements. – PC. Jan 10 '12 at 16:35
-1

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.

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?). 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. Technically, it's home2 that is the default home. Primitive, I'm sure, but effective nevertheless. A proof of concept, if nothing else.

Li Rys
  • 1