xamarin - Android Setting New default home in code -
i have app want set default home screen, i'm running unusual problem.
i have setting allows user select default home screen.
i utilize next code allow them select default activity:
intent selector = new intent(intent.actionmain); selector.addcategory(intent.categoryhome); selector.addcategory(intent.categorydefault); selector.setcomponent(new componentname("android", "com.android.internal.app.resolveractivity")); startactivity(selector);
with no default set, run code , select app default , tell utilize that.
now, run code again, , tell utilize different activity (not mine) , utilize it.
the problem is, never switches different if default set.
i've seen other applications allow this, i'm missing something, don't know what.
i'm testing on samsung galaxy s4 api level set 14.
ok, found reply question.
the reply here: http://www.trustydroid.com/2014/05/19/force-show-default-app-chooser-dialog/
the 1 thing should maintain in mind component name must correct. apparently under api14, ignores component (and acts works) if class name not correct. goes through motions of enabling component, launching chooser, disabling component. however, never saves new default.
after tried compiling under api19, os threw exception lead me prepare issue having working (which wrong class name).
once had straightened out, did wanted.
for completeness sake, here code:
create fakeactivity this:
[activity(label = "fakelauncher", enabled = false)] [intentfilter(new[] { intent.actionmain }, categories = new[] { intent.categoryhome, intent.categorydefault })] public class fakelauncher : activity { protected override void oncreate(bundle bundle) { base.oncreate(bundle); // create application here } }
then ever want alter default home run code:
componentname componentname = new componentname(application.packagename, "<fake activity class name>"); packagemanager.setcomponentenabledsetting(componentname, android.content.pm.componentenabledstate.enabled, android.content.pm.componentenableoption.dontkillapp); intent tempintent = new intent(intent.actionmain); tempintent.addcategory(intent.categoryhome); startactivity(tempintent); packagemanager.setcomponentenabledsetting(componentname, android.content.pm.componentenabledstate.disabled, android.content.pm.componentenableoption.dontkillapp);
android xamarin
No comments:
Post a Comment