繁体   English   中英

何时启动器函数被调用的侦听器

[英]Listener for when the launcher function is called

我正在进行启动器活动,我希望当用户按下主页按钮时,仅当启动器活动在屏幕上运行时,它将进入启动器活动。 调用启动器函数时是否有侦听器? 当我说启动器时,我的意思是像应用程序Nova Launcher一样,当您按下主屏幕时它将接管主屏幕。

我的活动清单设置如下:

<activity
            android:name="com.example.lock.LockscreenActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
            android:screenOrientation="portrait"
            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>

或者,就像清单中的内容一样容易。

谢谢!

将此添加到您要启动的活动中(在清单中):

<intent-filter>

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

        </intent-filter>

如果按主屏幕,则可以选择要启动的活动,默认活动或自定义活动。 您可以将自己设置为默认值,并且在启动手机时它将自动启动。

它为我工作。 这个网志还有更多内容: http : //arnab.ch/blog/2013/08/how-to-write-custom-launcher-app-in-android/

您是否在真实设备上尝试过?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM