how to make the Launcher-Pick-Up popup window showing?

廉价感情. 提交于 2019-12-04 18:07:39

launcher can only clear its own prefered settings for security issue.

here is a work around:

register a mockup activity in Manifest.xml:

   <activity
        android:name="MockupLauncher"
        android:enabled="false" 
        android:exported="false" 
        android:excludeFromRecents="true" 
        android:launchMode="singleTask" >

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

use "PackageManager.setComponentEnabledSetting" to trigger OS clear current prefered launcher:

    private void resetPreferedLauncher() {

       PackageManager pm = mContext.getPackageManager();
       ComponentName mockupComponent = new  ComponentName(MockupLauncher.class.getPackage().getName(), MockupLauncher.class.getName());

       pm.setComponentEnabledSetting(mockupComponent,  PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

      Intent startMain = new Intent(Intent.ACTION_MAIN);
      startMain.addCategory(Intent.CATEGORY_HOME);
      startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      mContext.startActivity(startMain);

      pm.setComponentEnabledSetting(mockupComponent,  PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
      // or
      //pm.setComponentEnabledSetting(mockupComponent, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
   }

that is how I make it! enjoy!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!