Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 777853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:40:28+00:00 2026-05-14T19:40:28+00:00

In SDK 1.5 I was using the PackageManager class to set the preferred home

  • 0

In SDK 1.5 I was using the PackageManager class to set the preferred home screen to be my app using PackageManager.addPackageToPreferred(). In the new SDK (using 2.1) this has been deprecated so I’m trying to use addPreferredActivity() for the same result but it’s not working as expected.

Some necessary background. I’m writing a lock screen replacement app so I want the home key to launch my app (which will already be running, hence having the effect of disabling the key). When the user "unlocks" the screen I intend to restore the mapping so everything works as normal.

In my AndroidManifest.xml I have:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.HOME"/>
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<uses-permission android:name="android.permission.SET_PREFERRED_APPLICATIONS">
</uses-permission>

In my code I have the following snippet:

// Set as home activity
// This is done so we can appear to disable the Home key.
PackageManager pm = getPackageManager();
//pm.addPackageToPreferred(getPackageName());
    
IntentFilter filter = new IntentFilter("android.intent.action.MAIN");
filter.addCategory("android.intent.category.HOME");
filter.addCategory("android.intent.category.DEFAULT");
    
ComponentName[] components = new ComponentName[] 
{
    new ComponentName("com.android.launcher", ".Launcher")
};
    
Context context = getApplicationContext();
ComponentName component = new ComponentName(context.getPackageName(),
MyApp.class.getName());
    
pm.clearPackagePreferredActivities("com.android.launcher");
pm.addPreferredActivity(filter, IntentFilter.MATCH_CATEGORY_EMPTY,
components, component);

The resulting behavior is that the app chooser comes up when I press the Home key, which indicates that the clearPackagePreferredActivities() call worked but my app did not get added as the preferred. Also, the first line in the log below says something about "dropping preferred activity for Intent":

04-06 02:34:42.379: INFO/PackageManager(1017): Result set changed, dropping preferred activity for Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 } type null

04-06 02:34:42.379: INFO/ActivityManager(1017): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=android/com.android.internal.app.ResolverActivity }

Does anyone know what this first log message means? Maybe I’m not using the API correctly, any ideas? Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:40:29+00:00Added an answer on May 14, 2026 at 7:40 pm

    @afonseca: I was dealing with the same problem. Thanks for the code, I used it to start with. Also thanks Shimon. I merged his answer into mine. I’ve got the code working (on 1.6 and 2.1 update 1). It has been adjusted a little bit, but the 2 main change seem to be Shimons suggestion and: “.Launcher” was changed to “com.android.launcher.Launcher”. The working code is posted below.

    Ciao, a2ronus

    PackageManager pm = getPackageManager();
    
    IntentFilter filter = new IntentFilter();
    filter.addAction("android.intent.action.MAIN");
    filter.addCategory("android.intent.category.HOME");
    filter.addCategory("android.intent.category.DEFAULT");
    
    Context context = getApplicationContext();
    ComponentName component = new ComponentName(context.getPackageName(), TestReplaceHomeAppActivity.class.getName());
    
    ComponentName[] components = new ComponentName[] {new ComponentName("com.android.launcher", "com.android.launcher.Launcher"), component};
    
    pm.clearPackagePreferredActivities("com.android.launcher");
    pm.addPreferredActivity(filter, IntentFilter.MATCH_CATEGORY_EMPTY, components, component);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am using SDK 4.1 to build an iPhone app and I set
I am using Android SDK 16.1 with Eclipse on Windows. I've set ANDROID_LINT_COMPLETE_REGIONS as
How to draw rectangle something like this in iphone sdk using core graphics
I imported ApiDemos from android-sdk folder using File/New/Project/Android Project/Create Project Existing Samples. When I
I've seen the GWT Expenses app from GWT SDK is using single module structure.
I'm pretty sure this is a limitation of the Windows Azure SDK (Using the
im making an app using SDK 7 (aos 2.1). But my app refuses to
I study iOS SDK using this book and in 4 Chapter, when it tells
I am successfully debugging my Android app on the NOOK SDK and using the
I used to find the flashlight is available or not using this code context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.