アプリのインストール場所
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
API レベル 8 以降では、外部ストレージ(デバイスの SD カードなど)へのアプリのインストールを許可できます。これは、アプリに対して android:installLocation
マニフェスト属性で宣言できるオプションの機能です。この属性を宣言しなければ、アプリは内部ストレージのみにインストールされ、外部ストレージには移動できません。
外部ストレージへのアプリのインストールをシステムに許可するには、マニフェスト ファイルを変更して <manifest>
要素に android:installLocation
属性を追加し、値を preferExternal
または auto
に設定します。次に例を示します。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="preferExternal"
... >
preferExternal
を宣言した場合は、外部ストレージへのアプリのインストールをリクエストしたことを意味しますが、システムが外部ストレージにアプリをインストールする保証はありません。外部ストレージに空き領域がなければ、内部ストレージにインストールされます。また、ユーザーは 2 つの場所の間でアプリを移動できます。
auto
を宣言した場合は、アプリを外部ストレージにインストールしてもよいがインストール場所は指定しないことを意味します。システムは、さまざまな要因に基づいて、アプリをインストールする場所を決定します。また、ユーザーは 2 つの場所の間でアプリを移動できます。
アプリが外部ストレージにインストールされた場合、次のようになります。
- 外部ストレージがデバイスにマウントされている限り、アプリのパフォーマンスは影響を受けません。
.apk
ファイルは外部ストレージに保存されますが、すべてのプライベート ユーザーデータ、データベース、最適化された .dex
ファイル、抽出されたネイティブ コードは内部デバイスメモリに保存されます。
- アプリが格納される一意のコンテナは、ランダムに生成された鍵で暗号化されます。この鍵を復号できるのは、アプリが最初にインストールされたデバイスだけです。したがって、SD カードにインストールされたアプリは 1 つのデバイスでのみ動作します。
- ユーザーは、システム設定を介してアプリを内部ストレージに移動できます。
警告: ユーザーが USB マスストレージを有効にしてパソコンとファイルを共有したときや、システム設定を介して SD カードのマウントを解除したときは、外部ストレージがデバイスからマウント解除され、外部ストレージで実行されているすべてのアプリは直ちに強制終了されます。
下位互換性
外部ストレージにアプリをインストールする機能は、API レベル 8(Android 2.2)以上を搭載したデバイスでのみ利用できます。API レベル 8 より前にビルドされた既存のアプリは、常に内部ストレージにインストールされ、外部ストレージ(API レベル 8 を搭載したデバイスも含む)には移動できません。ただし、アプリが API レベル 8 未満をサポートするように設計されている場合、API レベル 8 以上を搭載したデバイスでこの機能をサポートしつつ、API レベル 8 未満を使用するデバイスとの互換性を維持することを選択できます。
外部ストレージへのインストールを許可し、API レベル 8 未満のバージョンとの互換性を維持するには:
<manifest>
要素に android:installLocation
属性を含め、値として auto
または preferExternal
を指定します。
android:minSdkVersion
属性をそのまま(8 未満の数値)にして、アプリコードではそのレベルと互換性のある API のみを使用するようにします。
- アプリをコンパイルするため、ビルド ターゲットを API レベル 8 に変更します。古い Android ライブラリは
android:installLocation
属性を理解せず、この属性があるとアプリがコンパイルされないので、この変更が必要です。
API レベル 8 未満を搭載したデバイスにアプリをインストールすると、android:installLocation
属性は無視され、アプリは内部ストレージにインストールされます。
注意: このような XML マークアップは古いプラットフォームでは無視されますが、minSdkVersion
が 8 未満のときは API レベル 8 で導入されたプログラミング API を使用しないように注意してください。ただし、コード内で下位互換性を維持するために必要な作業を実施する場合は別です。
外部ストレージにインストールすべきでないアプリ
ユーザーが USB マスストレージを有効にしてパソコンとファイルを共有したとき(または外部ストレージのマウントを解除したか取り外したとき)、外部ストレージにインストールされた現在実行中のアプリはすべて強制終了されます。マスストレージを無効にして外部ストレージをデバイスに再度マウントするまで、システムは事実上アプリを認識しません。つまり、アプリが強制終了されてユーザーが利用できなくなるだけでなく、アプリのタイプによっては深刻な障害が発生するおそれがあります。アプリを常に想定どおりに動作させるためには、アプリが次の機能のいずれかを使用する場合、外部ストレージへのアプリのインストールを許可すべきではありません。外部ストレージのマウントが解除されたときに、次のような結果が生じるからです。
- サービス
- 実行中の
Service
は強制終了され、外部ストレージを再度マウントしても再起動しません。このサービスにバインドされているアプリは、ACTION_EXTERNAL_APPLICATIONS_AVAILABLE
ブロードキャスト インテントを登録できます。このインテントは、外部ストレージにインストールされているアプリをシステムが再び利用できるようになったとき、外部ストレージにインストールされていないすべてのアプリにそのことを通知します。アプリはこのブロードキャストを受信した後、サービスへのバインドを試みることができます。
- アラーム サービス
AlarmManager
で登録されたアラームはキャンセルされます。外部ストレージを再度マウントするときに、手動でアラームを再登録する必要があります。
- インプット メソッド エンジン
- ユーザーが使用している IME は、デフォルトの IME に置き換えられます。外部ストレージを再度マウントしたとき、ユーザーはシステム設定を開いて自分が使用する IME を再度有効にできます。
- ライブ壁紙
- ユーザーが実行しているライブ壁紙は、デフォルトのライブ壁紙に置き換えられます。外部ストレージを再度マウントしたとき、ユーザーは自分が実行するライブ壁紙を再度選択できます。
- アプリ ウィジェット
- ユーザーが使用しているアプリ ウィジェットは、ホーム画面から削除されます。外部ストレージを再度マウントしても、システムがホームアプリをリセットするまで(通常はシステムを再起動するまで)、ユーザーは外部ストレージにあるアプリ ウィジェットを選択できません。
- アカウント マネージャー
AccountManager
で作成されたアカウントは、外部ストレージが再度マウントされるまで表示されません。
- 同期アダプター
- ユーザーが使用している
AbstractThreadedSyncAdapter
とそのすべての同期機能は、外部ストレージが再度マウントされるまで機能しません。
- デバイス管理
- ユーザーが使用している
DeviceAdminReceiver
とそのすべての管理機能は無効になり、それによってデバイスの機能に予測不能な影響が生じる可能性があります。その影響は外部ストレージを再度マウントした後も続く場合があります。
- 「起動の完了」をリッスンするブロードキャスト レシーバ
- 外部ストレージがデバイスにマウントされる前に、システムは
ACTION_BOOT_COMPLETED
ブロードキャストを配信します。外部ストレージにインストールされているアプリは、このブロードキャストを受信できません。
アプリが上記の機能のいずれかを使用する場合は、外部ストレージへのアプリのインストールを許可すべきではありません。デフォルトでは、システムは外部ストレージへのアプリのインストールを許可しません。したがって、既存のアプリに関する心配は不要です。しかし、アプリを外部ストレージにインストールすべきでないという確信がある場合は、android:installLocation
に値 internalOnly
を指定して宣言することにより、そのことを明確に示す必要があります。この宣言によってデフォルトの動作が変更されることはありませんが、アプリが内部ストレージにのみインストールされるべきであると明示的に表明し、この決定がなされたことを自分自身と他のデベロッパーにリマインダーとして知らせることができます。
外部ストレージにインストールすべきアプリ
簡単に言うと、前のセクションで挙げた機能を使用しないアプリやサービスは、外部ストレージにインストールしても安全です。一般的に、サイズの大きいゲームは外部ストレージへのインストールを許可すべきタイプのアプリです。通常、ゲームはアクティブでないときは追加のサービスを提供しないからです。外部ストレージが利用できなくなりゲームプロセスが強制終了された場合、ストレージが再び利用可能になってユーザーがゲームを再起動したとき、(通常のアクティビティ ライフサイクルでゲームの状態が正常に保存されていれば)目に見える影響は何もないはずです。
APK ファイル用に数メガバイトを必要とするアプリについては、ユーザーが内部ストレージの空き容量を確保できるように、外部ストレージにアプリをインストールできるかどうかを慎重に検討すべきです。
その他の関連情報については、<manifest> をご覧ください。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-27 UTC。"],[],[],null,["# App install location\n\nBeginning with API Level 8, you can allow your application to be installed on the\nexternal storage (for example, the device's SD card). This is an optional feature you can declare\nfor your application with the [`android:installLocation`](/guide/topics/manifest/manifest-element#install) manifest attribute. If you do\n*not* declare this attribute, your application will be installed on the internal storage\nonly and it cannot be moved to the external storage.\n\nTo allow the system to install your application on the external storage, modify your\nmanifest file to include the [`android:installLocation`](/guide/topics/manifest/manifest-element#install) attribute in the [\u003cmanifest\u003e](/guide/topics/manifest/manifest-element) element,\nwith a value of either \"`preferExternal`\" or \"`auto`\". For example: \n\n```xml\n\u003cmanifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:installLocation=\"preferExternal\"\n ... \u003e\n```\n\nIf you declare \"`preferExternal`\", you request that your application be installed on the\nexternal storage, but the system does not guarantee that your application will be installed on\nthe external storage. If the external storage is full, the system will install it on the internal\nstorage. The user can also move your application between the two locations.\n\nIf you declare \"`auto`\", you indicate that your application may be installed on the\nexternal storage, but you don't have a preference of install location. The system will\ndecide where to install your application based on several factors. The user can also move your\napplication between the two locations.\n\nWhen your application is installed on the external storage:\n\n- There is no effect on the application performance so long as the external storage is mounted on the device.\n- The `.apk` file is saved on the external storage, but all private user data, databases, optimized `.dex` files, and extracted native code are saved on the internal device memory.\n- The unique container in which your application is stored is encrypted with a randomly generated key that can be decrypted only by the device that originally installed it. Thus, an application installed on an SD card works for only one device.\n- The user can move your application to the internal storage through the system settings.\n\n**Warning:** When the user enables USB mass storage to share files\nwith a computer or unmounts the SD card via the system settings, the external storage is unmounted\nfrom the device and all applications running on the external storage are immediately killed.\n\nBackward compatibility\n----------------------\n\nThe ability for your application to install on the external storage is a feature available only\non devices running API Level 8 (Android 2.2) or greater. Existing applications that were built prior\nto API Level 8 will always install on the internal storage and cannot be moved to the external\nstorage (even on devices with API Level 8). However, if your application is designed to support an\nAPI Level *lower than* 8, you can choose to support this feature for devices with API Level 8\nor greater and still be compatible with devices using an API Level lower than 8.\n\nTo allow installation on external storage and remain compatible with versions lower than API\nLevel 8:\n\n1. Include the `android:installLocation` attribute with a value of \"`auto`\" or \"`preferExternal`\" in the [\u003cmanifest\u003e](/guide/topics/manifest/uses-sdk-element) element.\n2. Leave your `android:minSdkVersion` attribute as is (something *less\n than* \"8\") and be certain that your application code uses only APIs compatible with that level.\n3. In order to compile your application, change your build target to API Level 8. This is necessary because older Android libraries don't understand the `android:installLocation` attribute and will not compile your application when it's present.\n\nWhen your application is installed on a device with an API Level lower than 8, the `android:installLocation` attribute is ignored and the application is installed on the internal\nstorage.\n\n**Caution:** Although XML markup such as this will be ignored by\nolder platforms, you must be careful not to use programming APIs introduced in API Level 8\nwhile your `minSdkVersion` is less than \"8\", unless you perform the work necessary to\nprovide backward compatibility in your code.\n\nApplications that should NOT install on external storage\n--------------------------------------------------------\n\nWhen the user enables USB mass storage to share files with their computer (or otherwise\nunmounts or removes the external storage), any application\ninstalled on the external storage and currently running is killed. The system effectively becomes\nunaware of the application until mass storage is disabled and the external storage is\nremounted on the device. Besides killing the application and making it unavailable to the user,\nthis can break some types of applications in a more serious way. In order for your application to\nconsistently behave as expected, you **should not** allow your application to be\ninstalled on the external storage if it uses any of the following features, due to the cited\nconsequences when the external storage is unmounted:\n\nServices\n: Your running\n [Service](/reference/android/app/Service) is\n killed and isn't restarted when external storage is remounted. Applications\n bound to this service can register for the\n [ACTION_EXTERNAL_APPLICATIONS_AVAILABLE](/reference/android/content/Intent#ACTION_EXTERNAL_APPLICATIONS_AVAILABLE)\n broadcast intent, which notifies all applications that *aren't*\n installed on external storage when the applications installed on external\n storage have become available to the system again. After receiving this\n broadcast, applications can attempt to bind to your service.\n\nAlarm Services\n: Your alarms registered with [AlarmManager](/reference/android/app/AlarmManager) will be cancelled. You must\n manually re-register any alarms when external storage is remounted.\n\nInput Method Engines\n: Your [IME](/guide/topics/text/creating-input-method) will be\n replaced by the default IME. When external storage is remounted, the user can open system settings\n to enable your IME again.\n\nLive Wallpapers\n: Your running [Live Wallpaper](http://android-developers.blogspot.com/2010/02/live-wallpapers.html)\n will be replaced by the default Live Wallpaper. When external storage is remounted, the user can\n select your Live Wallpaper again.\n\nApp Widgets\n: Your [App Widget](/guide/topics/appwidgets) will be removed\n from the home screen. When external storage is remounted, your App Widget will *not* be\n available for the user to select until the system resets the home application (usually not until a\n system reboot).\n\nAccount Managers\n: Your accounts created with [AccountManager](/reference/android/accounts/AccountManager) will disappear until\n external storage is remounted.\n\nSync Adapters\n: Your [AbstractThreadedSyncAdapter](/reference/android/content/AbstractThreadedSyncAdapter) and all its sync functionality will\n not work until external storage is remounted.\n\nDevice Administrators\n: Your [DeviceAdminReceiver](/reference/android/app/admin/DeviceAdminReceiver) and all its admin capabilities will\n be disabled, which can have unforeseeable consequences for the device functionality, which may\n persist after external storage is remounted.\n\nBroadcast Receivers listening for \"boot completed\"\n: The system delivers the [ACTION_BOOT_COMPLETED](/reference/android/content/Intent#ACTION_BOOT_COMPLETED) broadcast\n before the external storage is mounted to the device. If your application is installed on the\n external storage, it can never receive this broadcast.\n\nIf your application uses any of the features listed above, you **should not** allow\nyour application to install on external storage. By default, the system *will not* allow your\napplication to install on the external storage, so you don't need to worry about your existing\napplications. However, if you're certain that your application should never be installed on the\nexternal storage, then you should make this clear by declaring [`android:installLocation`](/guide/topics/manifest/manifest-element#install) with a value of \"`internalOnly`\". Though this does not\nchange the default behavior, it explicitly states that your application should only be installed\non the internal storage and serves as a reminder to you and other developers that this decision has\nbeen made.\n\nApplications that should install on external storage\n----------------------------------------------------\n\nIn simple terms, anything that does not use the features listed in the previous section\nare safe when installed on external storage. Large games are more commonly the types of\napplications that should allow installation on external storage, because games don't typically\nprovide additional services when inactive. When external storage becomes unavailable and a game\nprocess is killed, there should be no visible effect when the storage becomes available again and\nthe user restarts the game (assuming that the game properly saved its state during the normal\n[Activity lifecycle](/guide/components/activities#Lifecycle)).\n\nIf your application requires several megabytes for the APK file, you should\ncarefully consider whether to enable the application to install on the external storage so that\nusers can preserve space on their internal storage.\n\nFor additional related information, refer to:[\\\u003cmanifest\\\u003e](/guide/topics/manifest/manifest-element)"]]