簡體   English   中英

如何在 Android 上打開 Default Home App screen intent

[英]How to open Default Home App screen intent on Android

我正在開發一個用作家庭啟動器的應用程序。 我了解我無法以編程方式清除當前的家庭應用程序啟動器,但我希望引導用戶選擇我的應用程序。

我了解如何使用PackageManager檢查我的應用程序是否設置為家庭啟動器,但這並沒有給我設置家庭應用程序的方法。

我也嘗試過將Intent用於 select 一個家庭啟動器,但是這個打開的對話框並沒有為用戶提供選擇默認家庭啟動器的方法

 final Intent startMain = new Intent(Intent.ACTION_MAIN);
            startMain.addCategory(Intent.CATEGORY_HOME);
            startActivity(Intent.createChooser(startMain, "Choose Home App));

但是看着Launcher (Nova) ,我可以看到它似乎運行一個打開本機啟動器屏幕的意圖。 我該怎么做呢?

默認家庭應用程序選擇器

PackageManager packageManager = activity.getPackageManager();
ComponentName componentName = new ComponentName(activity, YourLauncher.class);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME)
        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
activity.startActivity(intent);
activity.finishAndRemoveTask();

和清單中的啟動器活動:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM