Creating Home Replacement app?

安稳与你 提交于 2020-01-03 04:51:18

问题


I want an application that acts as a Home Replacement app. There are several activities when you first launch the app that allow you to configure basic settings. Then you get to the Home Screen. In the Android Manifest, I have added the following lines:

    <activity android:name="com.tabletnanny.HomeScreenMain"
        android:theme="@style/Theme"
        android:launchMode="singleInstance"
        android:stateNotNeeded="true">
    <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>

Now what I want is the following: every time that the user gets to this activity, the box that prompts you which home screen you want to set as default pops up. This has to pop up no matter what every time the app is launched, even if during a previous launch, the user accidentally selected the wrong Home Screen "Always". I also have an "Exit" button on this Home Screen. Tapping the "Exit" button will bring up this dialog box once again and allow you to select the default Home Screen again. How can I do this in the java code?


回答1:


Android makes this pretty easy - just build up an intent for launching home like so:

Intent home = new Intent(Intent.ACTION_MAIN);
home.addCategory(Intent.CATEGORY_HOME);

Intent has a method that generates a "Chooser" Intent. the chooser intent launches a dialog showing all Activitys that can respond to the intent you created; in your case the "Home" category:

Intent chooser = Intent.createChooser(home, "Launcher");
mContext.startActivity(chooser);



回答2:


I don't think you can force the system to forget the user preference. Once the user preference is stored, it will only come back if an application gets updated or you install a new Launcher.

But you can force an intent you fire yourself to display the App chooser (solution for your "Exit" button) : see http://developer.android.com/training/basics/intents/sending.html#AppChooser



来源:https://stackoverflow.com/questions/17408262/creating-home-replacement-app

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