Android APP转成launcher

一、背景

       使用场景,需要开机的时候,自动启动app,解决方案为将Android app转成 launcher app,可实现效果。

二、实现

    在app入口activity 的配置文件(AndroidManifest.xml)对应位置,添加

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

案例代码:

  <activity
            android:name=".ui.activity.splash.SplashActivity"
            android:exported="true"
            android:largeHeap="true"
            android:persistent="true"
            android:theme="@style/Left_Right_AnimTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.HOME" />
            </intent-filter>

        </activity>

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Android中,可以通过检查应用程序的清单文件中的intent-filter来确定一个应用程序是否为启动器应用程序(LAUNCHER_APP)。一个具有以下清单文件的应用程序将被认为是启动器应用程序: ``` <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.launcherapp"> <application> <activity android:name=".LauncherActivity" android:label="@string/app_name"> <!-- This intent filter identifies this activity as the main entry point --> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> ``` 这里,我们使用了`android.intent.category.LAUNCHER`意图过滤器来标识此应用程序作为启动器应用程序,因为该过滤器指示此活动为该应用程序的主要入口点。 如果您想在代码中编程检查一个应用程序是否为启动器应用程序,您可以使用PackageManager的getLaunchIntentForPackage()方法。如果返回的Intent对象包含`CATEGORY_LAUNCHER`类别,则该应用程序被认为是启动器应用程序。以下是一个示例: ``` PackageManager pm = getPackageManager(); Intent launchIntent = pm.getLaunchIntentForPackage("com.example.launcherapp"); Set<String> categories = launchIntent.getCategories(); if (categories != null && categories.contains(Intent.CATEGORY_LAUNCHER)) { // The app is a launcher app } else { // The app is not a launcher app } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值