How do i declare my Activity as Launcher?

对着背影说爱祢 提交于 2019-12-25 18:23:09

问题


I am trying to build a kind of custom lockscreen.

In order to achieve that I need to disable the HOME button.

From this post I understand that I can achieve that by declaring my Activity as a Launcher.

Please how do I do that? (it is in the Manifest obviously) This is the Manifest. The Activity that "acts" as a lockscreen is LockScreen

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appengine.paranoid_android.lost"
android:versionCode="2"
android:versionName="1.1" >

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".InfoSetup"
        android:clearTaskOnLaunch="true"
        android:label="@string/activity_name"
        android:launchMode="singleTask" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".LockScreen"
        android:clearTaskOnLaunch="true"
        android:label="@string/activity_name"
        android:launchMode="singleInstance"
        android:theme="@android:style/Theme.NoTitleBar" >
        <service
            android:name=".InfoService"
            android:label="@string/service_name" />

        <receiver android:name="com.appengine.paranoid_android.lost.BootCompleteReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <action android:name="android.intent.action.PACKAGE_CHANGED" />
                <action android:name="android.intent.action.PACKAGE_REMOVED" />

                <data android:scheme="package" />
            </intent-filter>
        </receiver>
    </activity>
</application>

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<!-- <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/> -->
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" >
</uses-sdk>


回答1:


Move the intent filter to your activity

<activity
    android:name=".LockScreen"
    android:clearTaskOnLaunch="true"
    android:label="@string/activity_name"
    android:launchMode="singleInstance"
    android:theme="@android:style/Theme.NoTitleBar" >

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>


来源:https://stackoverflow.com/questions/16710769/how-do-i-declare-my-activity-as-launcher

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