清除和设置默认主页应用程序应用程序、主页

2023-09-12 02:53:23 作者:浮若淺笑

如何在世界上确实新星管理呢?我从字面上试图做同样的事情:为用户提供一个按钮,preSS清除,并挑选他们的新的缺省启动程序。

我能够得到默认的应用程序的名称,并显示它:

 私人字符串得到prefered(意向我){
       PackageManager PM = this.getActivity()getPackageManager()。
       最终ResolveInfo明复= pm.resolveActivity(ⅰ,0);
       返回(串)pm.getApplicationLabel(mInfo.activityInfo.applicationInfo);
   }
 

其中,意图我

 意图家庭=新的意向书(android.intent.action.MAIN);
        home.addCategory(android.intent.category.HOME);
 

然后,我调用系统ResolveActivity,

 私人无效化妆prefered(){
       意向选择=新的意向书(android.intent.action.MAIN);
       selector.addCategory(android.intent.category.HOME);
       selector.setComponent(新的组件名(机器人,com.android.internal.app.ResolverActivity));
       startActivity(选择);
   }
 
如何解决win10系统中无法更改的默认应用程序

机械手出现和正常运行,但它实际上并不设置或清除任何值。虽然调试它,它看来,如果我失去了一些额外的?当我打电话使prefered 的方法,我得到以下日志消息,

  I / ActivityManager(602):开始{行为= android.intent.action.MAIN猫= [android.intent.category.HOME] CMP =机器人/ com.android.internal .app.ResolverActivity U = 0}从PID 22641
 

当我用新星实现我看到这一切不过,

  I / PackageManager(602):结果集改变,下跌preferred活动的意向{行为= android.intent.action.MAIN猫= [android.intent.category。首页] FLG = 0x10200000(有群众演员)}类型为null
I / ActivityManager(602):开始{行为= android.intent.action.MAIN猫= [android.intent.category.HOME] FLG = 0x10200000 CMP =机器人/ com.android.internal.app.ResolverActivity(有群众演员)U = 0}从PID 22905
I / ActivityManager(602):开始{行为= android.intent.action.MAIN猫= [android.intent.category.HOME] FLG = 0x10200000 CMP = com.mycolorscreen.canvas / .Launcher(有临时演员)U = 0}从PID 22905
 

我怎样才能在那里,看看什么东西被连同包发送? 我如何才能清除preferred应用程序?不要告诉我你不能,我已经看够了那些答案。新星做它,做它正是我希望的方式。 解决方案

在code要做到这一点其实只是一个非常聪明的变通。

在与组件

 <类机器人:名称=android.intent.category.HOME/>
 

已启用,通常从一个新的家庭应用的安装,默认主页的应用程序被清除。

要利用这一点通过创建像这样的家庭组成一个空的活动。

 <活动
            机器人:名称=com.t3hh4xx0r.haxlauncher.FakeHome
            机器人:启用=假>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>
                <类机器人:名称=android.intent.category.HOME/>
                <类机器人:名称=android.intent.category.DEFAULT/>
            &所述; /意图滤光器>
        < /活性GT;
 

当您要设置新的默认情况下,启用该组件,然后调用家里意图 然后再次关闭你的假回家组件。

 公共静态无效的化妆prefered(上下文C){
       PackageManager p值= c.getPackageManager();
       组件名CN =新的组件名(C,FakeHome.class);
       p.setComponentEnabledSetting(CN,PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP);

       意向选择=新的意图(Intent.ACTION_MAIN);
       selector.addCategory(Intent.CATEGORY_HOME);
       c.startActivity(选择);

       p.setComponentEnabledSetting(CN,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP);
   }
 

最终的结果是,该系统认为是安装了一个新的家庭的应用程序,因此默认清除允许你设置你没有特殊的权限。

感谢您凯文从TeslaCoil和NovaLauncher关于如何做到这一点的信息!

How in the world does Nova manage this? I'm literally trying to do exactly the same thing: provide users with a button to press to clear and pick their new default launcher.

I'm able to get the default app name and display it:

       private String getPrefered(Intent i) {
       PackageManager pm = this.getActivity().getPackageManager();
       final ResolveInfo mInfo = pm.resolveActivity(i, 0);
       return (String) pm.getApplicationLabel(mInfo.activityInfo.applicationInfo);
   }

where Intent i is

Intent home = new Intent("android.intent.action.MAIN");
        home.addCategory("android.intent.category.HOME");

Then I call up the system ResolveActivity,

private void makePrefered() {
       Intent selector = new Intent("android.intent.action.MAIN");
       selector.addCategory("android.intent.category.HOME");                          
       selector.setComponent(new ComponentName("android", "com.android.internal.app.ResolverActivity"));
       startActivity(selector);
   }

The picker comes up and functions correctly, but it doesn't actually set or clear any values. While debugging it, it seems as if I'm missing some extras? When I call the makePrefered method, I get the following log message,

I/ActivityManager(  602): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] cmp=android/com.android.internal.app.ResolverActivity u=0} from pid 22641

When I use the Nova implementation I see all of this however,

    I/PackageManager(  602): Result set changed, dropping preferred activity for Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 (has extras) } type null
I/ActivityManager(  602): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=android/com.android.internal.app.ResolverActivity (has extras) u=0} from pid 22905
I/ActivityManager(  602): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.mycolorscreen.canvas/.Launcher (has extras) u=0} from pid 22905

How can I get in there and see what's being sent along with that bundle? How can I just clear the preferred app? Don't tell me you can't, I've seen enough of those answers. Nova does it and does it exactly the way that I would like to.

解决方案

The code to do this is actually just a very clever work around.

When a component with

        <category android:name="android.intent.category.HOME" />

is enabled, generally from an install of a new home application, the default home app gets cleared.

To take advantage of this by creating an empty activity with the home component like this.

<activity
            android:name="com.t3hh4xx0r.haxlauncher.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>     

When you want to set your new default, you enable this component, then call the home intent and then disable your fake home component again.

public static void makePrefered(Context c) {
       PackageManager p = c.getPackageManager();
       ComponentName cN = new ComponentName(c, 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);            
       c.startActivity(selector);

       p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
   }

The end result is that the system thinks a new home app was installed, so the default is cleared allowing you to set yours with no special permissions.

Thank you to Kevin from TeslaCoil and NovaLauncher for the information on how this is done!