android: choose default launcher programmatically
I want to pop up a dialog that lets the user choose a launcher to be launched with set as default option. I tried
Intent home = new Intent(Intent.ACTION_DEFAULT);
home.addCategory(Intent.CATEGORY_LAUNCHER);
Intent chooser = Intent.createChooser(home, "Launcher");
context.startActivity(chooser);
But the dialog popped by this does not have the option to set default. While the following code will not pop up the dialog if a default launcher is already set.
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
How can this be done?
android android-intent homescreen android-launcher
add a comment |
I want to pop up a dialog that lets the user choose a launcher to be launched with set as default option. I tried
Intent home = new Intent(Intent.ACTION_DEFAULT);
home.addCategory(Intent.CATEGORY_LAUNCHER);
Intent chooser = Intent.createChooser(home, "Launcher");
context.startActivity(chooser);
But the dialog popped by this does not have the option to set default. While the following code will not pop up the dialog if a default launcher is already set.
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
How can this be done?
android android-intent homescreen android-launcher
add a comment |
I want to pop up a dialog that lets the user choose a launcher to be launched with set as default option. I tried
Intent home = new Intent(Intent.ACTION_DEFAULT);
home.addCategory(Intent.CATEGORY_LAUNCHER);
Intent chooser = Intent.createChooser(home, "Launcher");
context.startActivity(chooser);
But the dialog popped by this does not have the option to set default. While the following code will not pop up the dialog if a default launcher is already set.
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
How can this be done?
android android-intent homescreen android-launcher
I want to pop up a dialog that lets the user choose a launcher to be launched with set as default option. I tried
Intent home = new Intent(Intent.ACTION_DEFAULT);
home.addCategory(Intent.CATEGORY_LAUNCHER);
Intent chooser = Intent.createChooser(home, "Launcher");
context.startActivity(chooser);
But the dialog popped by this does not have the option to set default. While the following code will not pop up the dialog if a default launcher is already set.
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
How can this be done?
android android-intent homescreen android-launcher
android android-intent homescreen android-launcher
edited Dec 29 '18 at 2:31
Cœur
17.6k9105145
17.6k9105145
asked Apr 16 '14 at 12:52
Vishnu Mohan GVishnu Mohan G
4421613
4421613
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try using the following:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
If a default action is already set (yours), you can call first:
getPackageManager().clearPackagePreferredActivities(getPackageName());
If the default action is not yours, you cannot clear it programmatically, what you can do is to check if other app is set as default and show a message..
private boolean isMyLauncherDefault() {
PackageManager localPackageManager = getPackageManager();
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
String str = localPackageManager.resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;
return str.equals(getPackageName());
}
As a workaround in case of other app is set as default, you can created a fake
home, install it (this will force the system to clear the default app) and then uninstall it...
Manifest.xml
<activity
android:name="FakeHome" android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
FakeHome.java
public class FakeHome extends Activity {
}
Somewhere
if(!isMyLauncherDefault()) {
PackageManager p = getPackageManager();
ComponentName cN = new ComponentName(Activity.this, FakeHome.class);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent selector = new Intent(Intent.ACTION_MAIN);
selector.addCategory(Intent.CATEGORY_HOME);
startActivity(selector);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
2
This code will not pop up the dialog if a default launcher is already set.
– Vishnu Mohan G
Apr 16 '14 at 13:10
Did you ever get this to work?
– portfoliobuilder
Jan 16 '15 at 20:15
Thefilters
parameter ofgetPreferredActivities()
is an output parameter. Adding a filter item to the list before the call has no effect.
– Christian d'Heureuse
Aug 21 '15 at 19:17
@Nermeen where this isMyLauncherDefault() is called?FakeHome Activity or any other activity? and where to pass the above intent?
– Rajesh
Mar 1 '16 at 9:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23110047%2fandroid-choose-default-launcher-programmatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try using the following:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
If a default action is already set (yours), you can call first:
getPackageManager().clearPackagePreferredActivities(getPackageName());
If the default action is not yours, you cannot clear it programmatically, what you can do is to check if other app is set as default and show a message..
private boolean isMyLauncherDefault() {
PackageManager localPackageManager = getPackageManager();
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
String str = localPackageManager.resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;
return str.equals(getPackageName());
}
As a workaround in case of other app is set as default, you can created a fake
home, install it (this will force the system to clear the default app) and then uninstall it...
Manifest.xml
<activity
android:name="FakeHome" android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
FakeHome.java
public class FakeHome extends Activity {
}
Somewhere
if(!isMyLauncherDefault()) {
PackageManager p = getPackageManager();
ComponentName cN = new ComponentName(Activity.this, FakeHome.class);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent selector = new Intent(Intent.ACTION_MAIN);
selector.addCategory(Intent.CATEGORY_HOME);
startActivity(selector);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
2
This code will not pop up the dialog if a default launcher is already set.
– Vishnu Mohan G
Apr 16 '14 at 13:10
Did you ever get this to work?
– portfoliobuilder
Jan 16 '15 at 20:15
Thefilters
parameter ofgetPreferredActivities()
is an output parameter. Adding a filter item to the list before the call has no effect.
– Christian d'Heureuse
Aug 21 '15 at 19:17
@Nermeen where this isMyLauncherDefault() is called?FakeHome Activity or any other activity? and where to pass the above intent?
– Rajesh
Mar 1 '16 at 9:53
add a comment |
Try using the following:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
If a default action is already set (yours), you can call first:
getPackageManager().clearPackagePreferredActivities(getPackageName());
If the default action is not yours, you cannot clear it programmatically, what you can do is to check if other app is set as default and show a message..
private boolean isMyLauncherDefault() {
PackageManager localPackageManager = getPackageManager();
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
String str = localPackageManager.resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;
return str.equals(getPackageName());
}
As a workaround in case of other app is set as default, you can created a fake
home, install it (this will force the system to clear the default app) and then uninstall it...
Manifest.xml
<activity
android:name="FakeHome" android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
FakeHome.java
public class FakeHome extends Activity {
}
Somewhere
if(!isMyLauncherDefault()) {
PackageManager p = getPackageManager();
ComponentName cN = new ComponentName(Activity.this, FakeHome.class);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent selector = new Intent(Intent.ACTION_MAIN);
selector.addCategory(Intent.CATEGORY_HOME);
startActivity(selector);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
2
This code will not pop up the dialog if a default launcher is already set.
– Vishnu Mohan G
Apr 16 '14 at 13:10
Did you ever get this to work?
– portfoliobuilder
Jan 16 '15 at 20:15
Thefilters
parameter ofgetPreferredActivities()
is an output parameter. Adding a filter item to the list before the call has no effect.
– Christian d'Heureuse
Aug 21 '15 at 19:17
@Nermeen where this isMyLauncherDefault() is called?FakeHome Activity or any other activity? and where to pass the above intent?
– Rajesh
Mar 1 '16 at 9:53
add a comment |
Try using the following:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
If a default action is already set (yours), you can call first:
getPackageManager().clearPackagePreferredActivities(getPackageName());
If the default action is not yours, you cannot clear it programmatically, what you can do is to check if other app is set as default and show a message..
private boolean isMyLauncherDefault() {
PackageManager localPackageManager = getPackageManager();
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
String str = localPackageManager.resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;
return str.equals(getPackageName());
}
As a workaround in case of other app is set as default, you can created a fake
home, install it (this will force the system to clear the default app) and then uninstall it...
Manifest.xml
<activity
android:name="FakeHome" android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
FakeHome.java
public class FakeHome extends Activity {
}
Somewhere
if(!isMyLauncherDefault()) {
PackageManager p = getPackageManager();
ComponentName cN = new ComponentName(Activity.this, FakeHome.class);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent selector = new Intent(Intent.ACTION_MAIN);
selector.addCategory(Intent.CATEGORY_HOME);
startActivity(selector);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
Try using the following:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
If a default action is already set (yours), you can call first:
getPackageManager().clearPackagePreferredActivities(getPackageName());
If the default action is not yours, you cannot clear it programmatically, what you can do is to check if other app is set as default and show a message..
private boolean isMyLauncherDefault() {
PackageManager localPackageManager = getPackageManager();
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
String str = localPackageManager.resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;
return str.equals(getPackageName());
}
As a workaround in case of other app is set as default, you can created a fake
home, install it (this will force the system to clear the default app) and then uninstall it...
Manifest.xml
<activity
android:name="FakeHome" android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
FakeHome.java
public class FakeHome extends Activity {
}
Somewhere
if(!isMyLauncherDefault()) {
PackageManager p = getPackageManager();
ComponentName cN = new ComponentName(Activity.this, FakeHome.class);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent selector = new Intent(Intent.ACTION_MAIN);
selector.addCategory(Intent.CATEGORY_HOME);
startActivity(selector);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
edited Nov 15 '18 at 9:55
Pascal
5,06513652
5,06513652
answered Apr 16 '14 at 12:55
NermeenNermeen
14.7k54664
14.7k54664
2
This code will not pop up the dialog if a default launcher is already set.
– Vishnu Mohan G
Apr 16 '14 at 13:10
Did you ever get this to work?
– portfoliobuilder
Jan 16 '15 at 20:15
Thefilters
parameter ofgetPreferredActivities()
is an output parameter. Adding a filter item to the list before the call has no effect.
– Christian d'Heureuse
Aug 21 '15 at 19:17
@Nermeen where this isMyLauncherDefault() is called?FakeHome Activity or any other activity? and where to pass the above intent?
– Rajesh
Mar 1 '16 at 9:53
add a comment |
2
This code will not pop up the dialog if a default launcher is already set.
– Vishnu Mohan G
Apr 16 '14 at 13:10
Did you ever get this to work?
– portfoliobuilder
Jan 16 '15 at 20:15
Thefilters
parameter ofgetPreferredActivities()
is an output parameter. Adding a filter item to the list before the call has no effect.
– Christian d'Heureuse
Aug 21 '15 at 19:17
@Nermeen where this isMyLauncherDefault() is called?FakeHome Activity or any other activity? and where to pass the above intent?
– Rajesh
Mar 1 '16 at 9:53
2
2
This code will not pop up the dialog if a default launcher is already set.
– Vishnu Mohan G
Apr 16 '14 at 13:10
This code will not pop up the dialog if a default launcher is already set.
– Vishnu Mohan G
Apr 16 '14 at 13:10
Did you ever get this to work?
– portfoliobuilder
Jan 16 '15 at 20:15
Did you ever get this to work?
– portfoliobuilder
Jan 16 '15 at 20:15
The
filters
parameter of getPreferredActivities()
is an output parameter. Adding a filter item to the list before the call has no effect.– Christian d'Heureuse
Aug 21 '15 at 19:17
The
filters
parameter of getPreferredActivities()
is an output parameter. Adding a filter item to the list before the call has no effect.– Christian d'Heureuse
Aug 21 '15 at 19:17
@Nermeen where this isMyLauncherDefault() is called?FakeHome Activity or any other activity? and where to pass the above intent?
– Rajesh
Mar 1 '16 at 9:53
@Nermeen where this isMyLauncherDefault() is called?FakeHome Activity or any other activity? and where to pass the above intent?
– Rajesh
Mar 1 '16 at 9:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23110047%2fandroid-choose-default-launcher-programmatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown