LoginSignup
2
1

More than 3 years have passed since last update.

[Android]ホーム・ランチャーアプリとして起動できるようにする

Last updated at Posted at 2020-11-21

Android では Home ボタンを押したときに特定のアプリを表示するようになっています。これを一般的にホームアプリやランチャーアプリと言います。例えば Microsoft Launcher などですねこれらをホーム・ランチャーアプリと呼びます。

image.png

ホーム・ランチャーアプリとして起動するには AndroidManifest.xml の Category にLAUNCHER とDEFAULT を追加します。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="jp.kaleidot725.sample">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Sample">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.Sample.NoActionBar"> 
            <intent-filter>
                <!-- android.intent.action.MAIN をつけるとこの Activity がアプリのエントリポイントになる -->
                <action android:name="android.intent.action.MAIN" />
                <!-- android.intent.category.HOME をつけると起動時に最初に起動する画面として認識される -->
                <category android:name="android.intent.category.HOME" />
                <!-- android.intent.category.LAUNCHER をつけるとホームボタンから起動できる画面として認識される -->
                <category android:name="android.intent.category.LAUNCHER" />
                <!-- android.intent.category.DEFAULT をつけると暗黙的インテントから起動できる画面として認識される -->
                <category android:name="android.intent.category.DEFAULT" />
          </intent-filter>
        </activity>
    </application>
</manifest>

LAUNCHER だけを設定すればランチャーアプリになるのではと思ってしまいますが、次のように Home ボタンを押したときに暗黙的インテント経由で起動をしなければならないのでDEFAULTも AndroidManifest.xml に記載しなければならないみたいです。

Nov-21-2020 21-45-49.gif

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1