<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> <meta content="IE=edge" http-equiv="X-UA-Compatible"> <link rel="shortcut icon" type="image/x-icon" href="../../../favicon.ico" /> <link rel="alternate" href="http://developer.android.com/training/basics/data-storage/files.html" hreflang="en" /> <link rel="alternate" href="http://developer.android.com/intl/es/training/basics/data-storage/files.html" hreflang="es" /> <link rel="alternate" href="http://developer.android.com/intl/id/training/basics/data-storage/files.html" hreflang="id" /> <link rel="alternate" href="http://developer.android.com/intl/ja/training/basics/data-storage/files.html" hreflang="ja" /> <link rel="alternate" href="http://developer.android.com/intl/ko/training/basics/data-storage/files.html" hreflang="ko" /> <link rel="alternate" href="http://developer.android.com/intl/pt-br/training/basics/data-storage/files.html" hreflang="pt-br" /> <link rel="alternate" href="http://developer.android.com/intl/ru/training/basics/data-storage/files.html" hreflang="ru" /> <link rel="alternate" href="http://developer.android.com/intl/vi/training/basics/data-storage/files.html" hreflang="vi" /> <link rel="alternate" href="http://developer.android.com/intl/zh-cn/training/basics/data-storage/files.html" hreflang="zh-cn" /> <link rel="alternate" href="http://developer.android.com/intl/zh-tw/training/basics/data-storage/files.html" hreflang="zh-tw" /> <title>Saving Files | Android Developers </title> <meta name="description" content="Android uses a file system that's similar to disk-based file systems on other platforms. This lesson describes how to work with the Android file system to read and write files with the File APIs. A File object is suited to reading or writing large…"> <!-- STYLESHEETS --> <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto+Condensed"> <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold" title="roboto"> <link href="../../../assets/css/default.css?v=16" rel="stylesheet" type="text/css"> <!-- JAVASCRIPT --> <script src="http://www.google.com/jsapi" type="text/javascript"></script> <script src="../../../assets/js/android_3p-bundle.js" type="text/javascript"></script> <script type="text/javascript"> var toRoot = "../../../"; var metaTags = ["datastorage"]; var devsite = false; var useUpdatedTemplates = false; </script> <script src="../../../assets/js/docs.js?v=17" type="text/javascript"></script> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-5831155-1', 'android.com'); ga('create', 'UA-49880327-2', 'android.com', {'name': 'universal'}); // New tracker); ga('send', 'pageview'); ga('universal.send', 'pageview'); // Send page view for new tracker. </script> </head> <body class="gc-documentation develop" itemscope itemtype="http://schema.org/Article"> <a name="top"></a> <!-- Header --> <div id="header-wrapper"> <div class="dac-header " id="header"> <div class="dac-header-inner"> <a class="dac-nav-toggle" data-dac-toggle-nav href="javascript:;" title="Open navigation"> <span class="dac-nav-hamburger"> <span class="dac-nav-hamburger-top"></span> <span class="dac-nav-hamburger-mid"></span> <span class="dac-nav-hamburger-bot"></span> </span> </a> <a class="dac-header-logo" href="../../../index.html"> <img class="dac-header-logo-image" src="../../../assets/images/android_logo.png" srcset="../../../assets/images/android_logo@2x.png 2x" width="32" height="36" alt="Android" /> Developers </a> <ul class="dac-header-tabs"> <li> <a class="dac-header-tab" href="../../../design/index.html" zh-tw-lang="設計" zh-cn-lang="设计" ru-lang="Проектирование" ko-lang="디자인" ja-lang="設計" es-lang="Diseñar">Design</a> </li> <li> <a class="dac-header-tab" href="../../../develop/index.html" zh-tw-lang="開發" zh-cn-lang="开发" ru-lang="Разработка" ko-lang="개발" ja-lang="開発" es-lang="Desarrollar">Develop</a> </li> <li> <a class="dac-header-tab" href="../../../distribute/index.html" zh-tw-lang="發佈" zh-cn-lang="分发" ru-lang="Распространение" ko-lang="배포" ja-lang="配布" es-lang="Distribuir">Distribute</a> </li> </ul> <a class="dac-header-console-btn" href="https://play.google.com/apps/publish/"> <span class="dac-sprite dac-google-play"></span> <span class="dac-visible-desktop-inline">Developer</span> Console </a> <form data-search class="dac-header-search"> <button class="dac-header-search-close" data-search-close> <i class="dac-sprite dac-back-arrow"></i> </button> <div class="dac-header-search-inner"> <i class="dac-sprite dac-search-white dac-header-search-icon"></i> <input id="search_autocomplete" type="text" value="" autocomplete="off" name="q" class="dac-header-search-input" placeholder="Search" /> <button class="dac-header-search-clear dac-hidden" data-search-clear> <i class="dac-sprite dac-close-black"></i> </button> </div> </form> </div><!-- end header-wrap.wrap --> </div><!-- end header --> </div> <!--end header-wrapper --> <!-- Navigation--> <nav class="dac-nav"> <div class="dac-nav-dimmer" data-dac-toggle-nav></div> <div class="dac-nav-sidebar" data-swap data-dynamic="false" data-transition-speed="300" data-dac-nav> <div data-swap-container> <a class="dac-nav-back-button dac-swap-section dac-up dac-no-anim" data-swap-button href="javascript:;"> <i class="dac-sprite dac-nav-back"></i> <span class="dac-nav-back-title">Back</span> </a> <div class="dac-nav-sub dac-swap-section dac-right dac-active" itemscope itemtype="http://schema.org/SiteNavigationElement"> <ul id="nav"> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/index.html"> Getting Started </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/basics/firstapp/index.html" description= "After you've installed the Android SDK, start with this class to learn the basics about Android app development." >Building Your First App</a> </div> <ul> <li><a href="../../../training/basics/firstapp/creating-project.html"> Creating an Android Project </a> </li> <li><a href="../../../training/basics/firstapp/running-app.html"> Running Your Application </a> </li> <li><a href="../../../training/basics/firstapp/building-ui.html"> Building a Simple User Interface </a> </li> <li><a href="../../../training/basics/firstapp/starting-activity.html"> Starting Another Activity </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/basics/supporting-devices/index.html" description= "How to build your app with alternative resources that provide an optimized user experience on multiple device form factors using a single APK." >Supporting Different Devices</a> </div> <ul> <li><a href="../../../training/basics/supporting-devices/languages.html"> Supporting Different Languages </a> </li> <li><a href="../../../training/basics/supporting-devices/screens.html"> Supporting Different Screens </a> </li> <li><a href="../../../training/basics/supporting-devices/platforms.html"> Supporting Different Platform Versions </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/basics/activity-lifecycle/index.html" ja-lang="アクティビティのライフサイクル 管理" ko-lang="액티비티 수명 주기 관리하기" pt-br-lang="Como gerenciar o ciclo de vida da atividade" ru-lang="Управление жизненным циклом операций" zh-cn-lang="管理活动生命周期" zh-tw-lang="管理應用行為顯示生命週期" description= "How Android activities live and die and how to create a seamless user experience by implementing lifecycle callback methods." >Managing the Activity Lifecycle</a> </div> <ul> <li><a href="../../../training/basics/activity-lifecycle/starting.html" ja-lang="アクティビティを開始する" ko-lang="액티비티 시작하기" pt-br-lang="Iniciando uma atividade" ru-lang="Запуск операции" zh-cn-lang="开始活动" zh-tw-lang="啟動應用行為顯示"> Starting an Activity </a> </li> <li><a href="../../../training/basics/activity-lifecycle/pausing.html"> Pausing and Resuming an Activity </a> </li> <li><a href="../../../training/basics/activity-lifecycle/stopping.html" ja-lang="アクティビティの一時停止と再開" ko-lang="액티비티 일시정지 및 재개하기" pt-br-lang="Pausando e reiniciando uma atividade" ru-lang="Приостановка и возобновление операции" zh-cn-lang="暂停和继续活动" zh-tw-lang="暫停並繼續應用行為顯示"> Stopping and Restarting an Activity </a> </li> <li><a href="../../../training/basics/activity-lifecycle/recreating.html" ja-lang="アクティビティを再作成する" ko-lang="액티비티 재생성하기" pt-br-lang="Recriando uma atividade" ru-lang="Воссоздание операции" zh-cn-lang="重新创建活动" zh-tw-lang="重新建立應用行為顯示"> Recreating an Activity </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/basics/fragments/index.html" description= "How to build a user interface for your app that is flexible enough to present multiple UI components on large screens and a more constrained set of UI components on smaller screens—essential for building a single APK for both phones and tablets." >Building a Dynamic UI with Fragments</a> </div> <ul> <li><a href="../../../training/basics/fragments/creating.html"> Creating a Fragment </a> </li> <li><a href="../../../training/basics/fragments/fragment-ui.html" zh-cn-lang="构建灵活的界面"> Building a Flexible UI </a> </li> <li><a href="../../../training/basics/fragments/communicating.html"> Communicating with Other Fragments </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"><a href="../../../training/basics/data-storage/index.html" ja-lang="データの保存" ko-lang="데이터 저장하기" pt-br-lang="Salvando dados" ru-lang="Сохранение данных" zh-cn-lang="保存数据" zh-tw-lang="儲存資料" description= "How to save data on the device, whether it's temporary files, downloaded app assets, user media, structured data, or something else." >Saving Data</a> </div> <ul> <li><a href="../../../training/basics/data-storage/shared-preferences.html" ja-lang="キー値セットを保存する" ko-lang="키-값 세트 저장하기" pt-br-lang="Salvando conjuntos de valor-chave" ru-lang="Сохранение наборов "\"ключ-значение\"" zh-cn-lang="保存键值集" zh-tw-lang="儲存索引鍵值組"> Saving Key-Value Sets </a> </li> <li><a href="../../../training/basics/data-storage/files.html" ja-lang="ファイルを保存する" ko-lang="파일 저장하기" pt-br-lang="Salvando arquivos" ru-lang="Сохранение файлов" zh-cn-lang="保存文件" zh-tw-lang="儲存檔案"> Saving Files </a> </li> <li><a href="../../../training/basics/data-storage/databases.html" ja-lang="SQL データベースにデータを保存する" ko-lang="SQL 데이터베이스에 데이터 저장하기" pt-br-lang="Salvando dados em bancos de dados do SQL" ru-lang="Сохранение данных в базах данных SQL" zh-cn-lang="在 SQL 数据库中保存数据" zh-tw-lang="在 SQL 資料庫中儲存資料"> Saving Data in SQL Databases </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/basics/intents/index.html" ja-lang="他のアプリとの相互操作" ko-lang="액티비티 수명 주기 관리하기" pt-br-lang="Interagindo com outros aplicativos" ru-lang="Взаимодействие с другими приложениями" zh-cn-lang="与其他应用交互" zh-tw-lang="與其他應用程式互動" description= "How to build a user experience that leverages other apps available on the device to perform advanced user tasks, such as capture a photo or view an address on a map." >Interacting with Other Apps</a> </div> <ul> <li><a href="../../../training/basics/intents/sending.html" ja-lang="別のアプリにユーザーを送る" ko-lang="다른 앱으로 사용자 보내기" pt-br-lang="Enviando o usuário para outro aplicativo" ru-lang="Направление пользователя в другое приложение" zh-cn-lang="向另一个应用发送用户" zh-tw-lang="將使用者傳送至其他應用程式"> Sending the User to Another App </a> </li> <li><a href="../../../training/basics/intents/result.html" ja-lang="アクティビティから結果を取得する" ko-lang="액티비티로부터 결과 가져오기" pt-br-lang="Obtendo resultados de uma atividade" ru-lang="Получение результата операции" zh-cn-lang="获取活动的结果" zh-tw-lang="從應用行為顯示取得結果"> Getting a Result from the Activity </a> </li> <li><a href="../../../training/basics/intents/filters.html" ja-lang="他のアプリからのアクティビティの開始を許可する" ko-lang="다른 앱이 자신의 액티비티를 시작하도록 허용하기" pt-br-lang="Permitindo que outros aplicativos iniciem sua atividade" ru-lang="Разрешение другим приложениям на запуск вашей операции" zh-cn-lang="允许其他应用开始您的活动" zh-tw-lang="允許其他應用程式啟動您的應用行為顯示"> Allowing Other Apps to Start Your Activity </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/permissions/index.html" description= "How to declare that your app needs access to features and resources outside of its 'sandbox', and how to request those privileges at runtime." >Working with System Permissions</a> </div> <ul> <li><a href="../../../training/permissions/declaring.html"> Declaring Permissions </a> </li> <li><a href="../../../training/permissions/requesting.html"> Requesting Permissions at Run Time </a> </li> <li><a href="../../../training/permissions/best-practices.html"> Best Practices for Runtime Permissions </a> </li> </ul> </li> </ul> </li><!-- end getting started --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/building-content-sharing.html"> <span class="small">Building Apps with</span><br/>Content Sharing </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/sharing/index.html" description= "How to take your app interaction to the next level by sharing information with other apps, receive information back, and provide a simple and scalable way to perform Share actions with user content." >Sharing Simple Data</a> </div> <ul> <li> <a href="../../../training/sharing/send.html"> Sending Simple Data to Other Apps </a> </li> <li> <a href="../../../training/sharing/receive.html"> Receiving Simple Data from Other Apps </a> </li> <li> <a href="../../../training/sharing/shareaction.html"> Adding an Easy Share Action </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/secure-file-sharing/index.html" description= "How to provide secure access to a file associated with your app using a content URI and temporary access permissions." >Sharing Files</a> </div> <ul> <li> <a href="../../../training/secure-file-sharing/setup-sharing.html"> Setting Up File Sharing </a> </li> <li> <a href="../../../training/secure-file-sharing/share-file.html"> Sharing a File </a> </li> <li> <a href="../../../training/secure-file-sharing/request-file.html"> Requesting a Shared File </a> </li> <li> <a href="../../../training/secure-file-sharing/retrieve-info.html"> Retrieving File Information </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/beam-files/index.html" description= "How to transfer files between devices using the NFC Android Beam feature." >Sharing Files with NFC</a> </div> <ul> <li> <a href="../../../training/beam-files/send-files.html" >Sending Files to Another Device</a> </li> <li><a href="../../../training/beam-files/receive-files.html" >Receiving Files from Another Device</a></li> </ul> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/building-multimedia.html"> <span class="small">Building Apps with</span><br/>Multimedia </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/managing-audio/index.html" description= "How to respond to hardware audio key presses, request audio focus when playing audio, and respond appropriately to changes in audio focus." >Managing Audio Playback</a> </div> <ul> <li><a href="../../../training/managing-audio/volume-playback.html"> Controlling Your App's Volume and Playback </a> </li> <li><a href="../../../training/managing-audio/audio-focus.html"> Managing Audio Focus </a> </li> <li><a href="../../../training/managing-audio/audio-output.html"> Dealing with Audio Output Hardware </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/camera/index.html" description= "How to leverage existing camera apps on the user's device to capture photos or control the camera hardware directly and build your own camera app." >Capturing Photos</a> </div> <ul> <li><a href="../../../training/camera/photobasics.html"> Taking Photos Simply </a> </li> <li><a href="../../../training/camera/videobasics.html"> Recording Videos Simply </a> </li> <li><a href="../../../training/camera/cameradirect.html"> Controlling the Camera </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/printing/index.html" description= "How to print photos, HTML documents, and custom documents from your app." >Printing Content</a> </div> <ul> <li><a href="../../../training/printing/photos.html"> Photos </a> </li> <li><a href="../../../training/printing/html-docs.html"> HTML Documents </a> </li> <li><a href="../../../training/printing/custom-docs.html"> Custom Documents </a> </li> </ul> </li> </ul> </li> <!-- End multimedia --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/building-graphics.html"> <span class="small">Building Apps with</span><br/>Graphics & Animation </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/displaying-bitmaps/index.html" description= "How to load and process bitmaps while keeping your user interface responsive and avoid exceeding memory limits." >Displaying Bitmaps Efficiently</a> </div> <ul> <li><a href="../../../training/displaying-bitmaps/load-bitmap.html"> Loading Large Bitmaps Efficiently </a> </li> <li><a href="../../../training/displaying-bitmaps/process-bitmap.html"> Processing Bitmaps Off the UI Thread </a> </li> <li><a href="../../../training/displaying-bitmaps/cache-bitmap.html"> Caching Bitmaps </a> </li> <li><a href="../../../training/displaying-bitmaps/manage-memory.html"> Managing Bitmap Memory </a> </li> <li><a href="../../../training/displaying-bitmaps/display-bitmap.html"> Displaying Bitmaps in Your UI </a></li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/graphics/opengl/index.html" description= "How to create OpenGL graphics within the Android app framework and respond to touch input." >Displaying Graphics with OpenGL ES</a> </div> <ul> <li><a href="../../../training/graphics/opengl/environment.html"> Building an OpenGL ES Environment </a> </li> <li><a href="../../../training/graphics/opengl/shapes.html"> Defining Shapes </a> </li> <li><a href="../../../training/graphics/opengl/draw.html"> Drawing Shapes </a> </li> <li><a href="../../../training/graphics/opengl/projection.html"> Applying Projection and Camera Views </a> </li> <li><a href="../../../training/graphics/opengl/motion.html"> Adding Motion </a> </li> <li><a href="../../../training/graphics/opengl/touch.html"> Responding to Touch Events </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/transitions/index.html" description= "How to animate state changes in a view hierarchy using transitions." >Animating Views Using Scenes and Transitions</a> </div> <ul> <li><a href="../../../training/transitions/overview.html"> The Transitions Framework </a> </li> <li><a href="../../../training/transitions/scenes.html"> Creating a Scene </a> </li> <li><a href="../../../training/transitions/transitions.html"> Applying a Transition </a> </li> <li><a href="../../../training/transitions/custom-transitions.html"> Creating Custom Transitions </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"><a href="../../../training/animation/index.html" description= "How to add transitional animations to your user interface."> Adding Animations </a></div> <ul> <li><a href="../../../training/animation/crossfade.html"> Crossfading Two Views </a> </li> <li><a href="../../../training/animation/screen-slide.html"> Using ViewPager for Screen Slide </a> </li> <li><a href="../../../training/animation/cardflip.html"> Displaying Card Flip Animations </a> </li> <li><a href="../../../training/animation/zoom.html"> Zooming a View </a> </li> <li><a href="../../../training/animation/layout.html"> Animating Layout Changes </a> </li> </ul> </li> </ul> </li> <!-- End graphics and animation --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/building-connectivity.html"> <span class="small">Building Apps with</span><br/> Connectivity & the Cloud </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/connect-devices-wirelessly/index.html" description= "How to find and connect to local devices using Network Service Discovery and how to create peer-to-peer connections with Wi-Fi." >Connecting Devices Wirelessly</a> </div> <ul> <li><a href="../../../training/connect-devices-wirelessly/nsd.html"> Using Network Service Discovery </a> </li> <li><a href="../../../training/connect-devices-wirelessly/wifi-direct.html"> Creating P2P Connections with Wi-Fi </a> </li> <li><a href="../../../training/connect-devices-wirelessly/nsd-wifi-direct.html"> Using Wi-Fi P2P for Service Discovery </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/basics/network-ops/index.html" description= "How to create a network connection, monitor the connection for changes in connectivity, and perform transactions with XML data." >Performing Network Operations</a> </div> <ul> <li><a href="../../../training/basics/network-ops/connecting.html"> Connecting to the Network </a> </li> <li><a href="../../../training/basics/network-ops/managing.html"> Managing Network Usage </a> </li> <li><a href="../../../training/basics/network-ops/xml.html"> Parsing XML Data </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/efficient-downloads/index.html" description= "How to minimize your app's impact on the battery when performing downloads and other network transactions." >Transferring Data Without Draining the Battery</a> </div> <ul> <li><a href="../../../training/efficient-downloads/efficient-network-access.html"> Optimizing Downloads for Efficient Network Access </a> </li> <li><a href="../../../training/efficient-downloads/regular_updates.html"> Minimizing the Effect of Regular Updates </a> </li> <li><a href="../../../training/efficient-downloads/redundant_redundant.html"> Redundant Downloads are Redundant </a> </li> <li><a href="../../../training/efficient-downloads/connectivity_patterns.html"> Modifying Patterns Based on the Connectivity Type </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/backup/index.html" description= "How to sync and back up app and user data to remote web services in the cloud and how to restore the data back to multiple devices." >Backing up App Data to the Cloud</a> </div> <ul> <li><a href="../../../training/backup/autosyncapi.html"> Configuring Auto Backup </a> </li> <li><a href="../../../training/backup/backupapi.html"> Using the Backup API </a> </li> </ul> <li><a href="../../../training/cloudsave/conflict-res.html" description= "How to design a robust conflict resolution strategy for apps that save data to the cloud." >Resolving Cloud Save Conflicts </a> </li> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/sync-adapters/index.html" description="How to transfer data between the cloud and the device using the Android sync adapter framework" >Transferring Data Using Sync Adapters</a> </div> <ul> <li> <a href="../../../training/sync-adapters/creating-authenticator.html"> Creating a Stub Authenticator </a> </li> <li> <a href="../../../training/sync-adapters/creating-stub-provider.html"> Creating a Stub Content Provider </a> </li> <li> <a href="../../../training/sync-adapters/creating-sync-adapter.html"> Creating a Sync Adapter </a> </li> <li> <a href="../../../training/sync-adapters/running-sync-adapter.html"> Running a Sync Adapter </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/volley/index.html" description="How to perform fast, scalable UI operations over the network using Volley" >Transmitting Network Data Using Volley</a> </div> <ul> <li> <a href="../../../training/volley/simple.html"> Sending a Simple Request </a> </li> <li> <a href="../../../training/volley/requestqueue.html"> Setting Up a RequestQueue </a> </li> <li> <a href="../../../training/volley/request.html"> Making a Standard Request </a> </li> <li> <a href="../../../training/volley/request-custom.html"> Implementing a Custom Request </a> </li> </ul> </li> </ul> </li> <!-- End connectivity and cloud --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/building-location.html"> <span class="small">Building Apps with</span><br/> Location & Maps </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/location/index.html" description="How to add location-aware features to your app by getting the user's current location."> Making Your App Location-Aware </a> </div> <ul> <li> <a href="../../../training/location/retrieve-current.html"> Getting the Last Known Location </a> </li> <li> <a href="../../../training/location/change-location-settings.html"> Changing Location Settings </a> </li> <li> <a href="../../../training/location/receive-location-updates.html"> Receiving Location Updates </a> </li> <li> <a href="../../../training/location/display-address.html"> Displaying a Location Address </a> </li> <li><a href="../../../training/location/geofencing.html"> Creating and Monitoring Geofences </a> </li> </ul> </li> <li class="nav-section"> <a href="../../../training/maps/index.html" description="How to add maps and mapping information to your app."> Adding Maps </a> </li> </ul> </li> <!-- End location and maps --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/building-userinfo.html"> <span class="small">Building Apps with</span><br/> User Info & Sign-In </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/contacts-provider/index.html" description= "How to use Android's central address book, the Contacts Provider, to display contacts and their details and modify contact information."> Accessing Contacts Data</a> </div> <ul> <li> <a href="../../../training/contacts-provider/retrieve-names.html"> Retrieving a List of Contacts </a> </li> <li> <a href="../../../training/contacts-provider/retrieve-details.html"> Retrieving Details for a Contact </a> </li> <li> <a href="../../../training/contacts-provider/modify-data.html"> Modifying Contacts Using Intents </a> </li> <li> <a href="../../../training/contacts-provider/display-contact-badge.html"> Displaying the Quick Contact Badge </a> </li> </ul> </li> <li class="nav-section"> <a href="../../../training/sign-in/index.html" description="How to add user sign-in functionality to your app."> Adding Sign-In </a> </li> </ul> </li> <!-- End user info and sign-in --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/building-wearables.html"> <span class="small">Building Apps for</span><br/> Wearables </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/wearables/notifications/index.html" description="How to build handheld notifications that are synced to and look great on wearables." >Adding Wearable Features to Notifications</a> </div> <ul> <li> <a href="../../../training/wearables/notifications/creating.html">Creating a Notification</a> </li> <li> <a href="../../../training/wearables/notifications/voice-input.html">Receiving Voice Input in a Notification</a> </li> <li> <a href="../../../training/wearables/notifications/pages.html">Adding Pages to a Notification</a> </li> <li> <a href="../../../training/wearables/notifications/stacks.html">Stacking Notifications</a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/wearables/apps/index.html" description="How to build apps that run directly on wearables." >Creating Wearable Apps</a> </div> <ul> <li> <a href="../../../training/wearables/apps/creating.html">Creating and Running a Wearable App</a> </li> <li> <a href="../../../training/wearables/apps/layouts.html">Creating Custom Layouts</a> </li> <li> <a href="../../../training/wearables/apps/always-on.html">Keeping Your App Visible</a> </li> <li> <a href="../../../training/wearables/apps/voice.html">Adding Voice Capabilities</a> </li> <li> <a href="../../../training/wearables/apps/packaging.html">Packaging Wearable Apps</a> </li> <li> <a href="../../../training/wearables/apps/bt-debugging.html">Debugging over Bluetooth</a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/wearables/ui/index.html" description="How to create custom user interfaces for wearable apps." >Creating Custom UIs</a> </div> <ul> <li> <a href="../../../training/wearables/ui/layouts.html">Defining Layouts</a> </li> <li> <a href="../../../training/wearables/ui/cards.html">Creating Cards</a> </li> <li> <a href="../../../training/wearables/ui/lists.html">Creating Lists</a> </li> <li> <a href="../../../training/wearables/ui/2d-picker.html">Creating a 2D Picker</a> </li> <li> <a href="../../../training/wearables/ui/confirm.html">Showing Confirmations</a> </li> <li> <a href="../../../training/wearables/ui/exit.html">Exiting Full-Screen Activities</a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/wearables/data-layer/index.html" description="How to sync data between handhelds and wearables." >Sending and Syncing Data</a> </div> <ul> <li> <a href="../../../training/wearables/data-layer/accessing.html">Accessing the Wearable Data Layer</a> </li> <li> <a href="../../../training/wearables/data-layer/data-items.html">Syncing Data Items</a> </li> <li> <a href="../../../training/wearables/data-layer/assets.html">Transferring Assets</a> </li> <li> <a href="../../../training/wearables/data-layer/messages.html">Sending and Receiving Messages</a> </li> <li> <a href="../../../training/wearables/data-layer/events.html">Handling Data Layer Events</a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/wearables/watch-faces/index.html" description="How to create watch faces for wearables." >Creating Watch Faces</a> </div> <ul> <li> <a href="../../../training/wearables/watch-faces/designing.html">Designing Watch Faces</a> </li> <li> <a href="../../../training/wearables/watch-faces/service.html">Building a Watch Face Service</a> </li> <li> <a href="../../../training/wearables/watch-faces/drawing.html">Drawing Watch Faces</a> </li> <li> <a href="../../../training/wearables/watch-faces/information.html">Showing Information in Watch Faces</a> </li> <li> <a href="../../../training/wearables/watch-faces/interacting.html">Creating Interactive Watch Faces</a> </li> <li> <a href="../../../training/wearables/watch-faces/configuration.html">Providing Configuration Activities</a> </li> <li> <a href="../../../training/wearables/watch-faces/issues.html">Addressing Common Issues</a> </li> <li> <a href="../../../training/wearables/watch-faces/performance.html">Optimizing Performance and Battery Life</a> </li> </ul> </li> <li> <a href="../../../training/articles/wear-location-detection.html" description= "How to detect location data on Android Wear devices." >Detecting Location</a> </li> <li> <a href="../../../training/articles/wear-permissions.html" description= "How to request permissions on Android Wear devices." >Requesting Permissions</a> </li> <li> <a href="../../../training/wearables/wearable-sounds.html" description= "How to use the speaker on Android Wear devices." >Using the Speaker</a> </li> </ul> </li> <!-- End Building for wearables --> <!-- Start: Building for TV --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/tv/index.html"> <span class="small">Building Apps for</span><br/> TV </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/tv/start/index.html" ja-lang="TV アプリのビルド" description="How to start building TV apps or extend your existing app to run on TV devices."> Building TV Apps</a> </div> <ul> <li> <a href="../../../training/tv/start/start.html" ja-lang="TV アプリのビルドを開始する"> Getting Started with TV Apps</a> </li> <li> <a href="../../../training/tv/start/hardware.html" ja-lang="TV ハードウェアを処理する"> Handling TV Hardware</a> </li> <li> <a href="../../../training/tv/start/layouts.html" ja-lang="TV 向けレイアウトをビルドする"> Building TV Layouts</a> </li> <li> <a href="../../../training/tv/start/navigation.html" ja-lang="TV 用のナビゲーションを作成する"> Creating TV Navigation</a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/tv/playback/index.html" ja-lang="TV 再生アプリのビルド" description="How to build apps that provide media catalogs and play content."> Building TV Playback Apps</a> </div> <ul> <li> <a href="../../../training/tv/playback/browse.html" ja-lang="カタログ ブラウザを作成する"> Creating a Catalog Browser</a> </li> <li> <a href="../../../training/tv/playback/card.html"> Providing a Card View</a> </li> <li> <a href="../../../training/tv/playback/details.html" ja-lang="詳細ビューをビルドする"> Building a Details View</a> </li> <li> <a href="../../../training/tv/playback/now-playing.html" ja-lang="再生中カードを表示する"> Displaying a Now Playing Card</a> </li> <li> <a href="../../../training/tv/playback/guided-step.html"> Adding a Guided Step</a> </li> <li> <a href="../../../training/tv/playback/options.html"> Enabling Background Playback</a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/tv/discovery/index.html" description="How to help users discover content from your app."> Helping Users Find Content on TV</a> </div> <ul> <li> <a href="../../../training/tv/discovery/recommendations.html"> Recommending TV Content</a> </li> <li> <a href="../../../training/tv/discovery/searchable.html"> Making TV Apps Searchable</a> <li> <a href="../../../training/tv/discovery/in-app-search.html"> Searching within TV Apps</a> </li> </ul> </li> <li> <a href="../../../training/tv/games/index.html" description="How to build games for TV."> Building TV Games</a> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/tv/tif/index.html" description="How to build channels for TV."> Building TV Channels</a> </div> <ul> <li> <a href="../../../training/tv/tif/tvinput.html"> Developing a TV Input Service</a> <li> <a href="../../../training/tv/tif/channel.html"> Working with Channel Data</a> </li> <li> <a href="../../../training/tv/tif/ui.html"> Managing User Interaction</a> </li> </ul> </li> <li> <a href="../../../training/tv/publishing/checklist.html" description="An itemized list of requirements for TV apps."> TV Apps Checklist</a> </li> </ul> </li> <!-- End: Building for TV --> <!-- Start: Building for Auto --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/auto/index.html"> <span class="small">Building Apps for</span><br/> Auto </a> </div> <ul> <li> <a href="../../../training/auto/start/index.html" description="How to start building or extending apps that work with Auto devices."> Getting Started with Auto</a> </li> <li> <a href="../../../training/auto/audio/index.html" description="How to extend audio apps to play content on Auto devices."> Playing Audio for Auto</a> </li> <li> <a href="../../../training/auto/messaging/index.html" description="How to extend text messaging apps to work with Auto devices."> Messaging for Auto</a> </li> <li> <a href="../../../training/auto/testing/index.html" description= "How to run and test Auto apps."> Testing Auto Apps</a> </li> </ul> </li> <!-- End: Building for Auto --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/best-ux.html"> <span class="small">Best Practices for</span><br/> Interaction & Engagement </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/design-navigation/index.html" description= "How to plan your app's screen hierarchy and forms of navigation so users can effectively and intuitively traverse your app content using various navigation patterns." >Designing Effective Navigation</a> </div> <ul> <li><a href="../../../training/design-navigation/screen-planning.html"> Planning Screens and Their Relationships </a> </li> <li><a href="../../../training/design-navigation/multiple-sizes.html"> Planning for Multiple Touchscreen Sizes </a> </li> <li><a href="../../../training/design-navigation/descendant-lateral.html"> Providing Descendant and Lateral Navigation </a> </li> <li><a href="../../../training/design-navigation/ancestral-temporal.html"> Providing Ancestral and Temporal Navigation </a> </li> <li><a href="../../../training/design-navigation/wireframing.html"> Putting it All Together: Wireframing the Example App </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/implementing-navigation/index.html" description= "How to implement various navigation patterns such as swipe views, a navigation drawer, and up navigation." >Implementing Effective Navigation</a> </div> <ul> <li><a href="../../../training/implementing-navigation/lateral.html"> Creating Swipe Views with Tabs </a> </li> <li><a href="../../../training/implementing-navigation/nav-drawer.html"> Creating a Navigation Drawer </a> </li> <li><a href="../../../training/implementing-navigation/ancestral.html"> Providing Up Navigation </a> </li> <li><a href="../../../training/implementing-navigation/temporal.html"> Providing Proper Back Navigation </a> </li> <li><a href="../../../training/implementing-navigation/descendant.html"> Implementing Descendant Navigation </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/notify-user/index.html" description= "How to display messages called notifications outside of your application's UI." >Notifying the User</a> </div> <ul> <li> <a href="../../../training/notify-user/build-notification.html"> Building a Notification </a> </li> <li> <a href="../../../training/notify-user/navigation.html"> Preserving Navigation when Starting an Activity </a> </li> <li> <a href="../../../training/notify-user/managing.html"> Updating Notifications </a> </li> <li> <a href="../../../training/notify-user/expanded.html"> Using Big View Styles </a> </li> <li> <a href="../../../training/notify-user/display-progress.html"> Displaying Progress in a Notification </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/swipe/index.html" description= "How to modify your app's layout to support manual content updates triggered by the swipe-to-refresh gesture." >Supporting Swipe-to-Refresh</a> </div> <ul> <li> <a href="../../../training/swipe/add-swipe-interface.html" >Adding Swipe-to-Refresh To Your App</a></li> <li> <a href="../../../training/swipe/respond-refresh-request.html" >Responding to a Refresh Gesture</a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/search/index.html" description= "How to properly add a search interface to your app and create a searchable database." >Adding Search Functionality</a> </div> <ul> <li><a href="../../../training/search/setup.html"> Setting up the Search Interface </a> </li> <li><a href="../../../training/search/search.html"> Storing and Searching for Data </a> </li> <li><a href="../../../training/search/backward-compat.html"> Remaining Backward Compatible </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/app-indexing/index.html" description= "How to enable deep linking and indexing of your application content so that users can open this content directly from their mobile search results." >Making Your App Content Searchable by Google</a> </div> <ul> <li><a href="../../../training/app-indexing/deep-linking.html"> Enabling Deep Links for App Content </a> </li> <li><a href="../../../training/app-indexing/enabling-app-indexing.html"> Specifying App Content for Indexing </a> </li> </ul> </li> <li> <a href="../../../training/articles/assistant.html" description= "Support contextually relevant actions through the Assist API." >Optimizing Content for the Assistant</a> </li> <li class="nav-section"> <div class="nav-section"> <a href="../../../training/app-links/index.html" description= "How to enable the system to handle web requests by taking the user directly to your app instead of your website." >Handling App Links</a> </div> </li> <!-- End Interaction and Engagement --> </ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/best-ui.html"> <span class="small">Best Practices for</span><br/> User Interface </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/multiscreen/index.html" zh-cn-lang="针对多种屏幕进行设计" ja-lang="複数画面のデザイン" es-lang="Cómo diseñar aplicaciones para varias pantallas" description= "How to build a user interface that's flexible enough to fit perfectly on any screen and how to create different interaction patterns that are optimized for different screen sizes." >Designing for Multiple Screens</a> </div> <ul> <li><a href="../../../training/multiscreen/screensizes.html" zh-cn-lang="支持各种屏幕尺寸" ko-lang="다양한 화면 크기 지원" ja-lang="さまざまな画面サイズのサポート" es-lang="Cómo admitir varios tamaños de pantalla" >Supporting Different Screen Sizes</a> </li> <li><a href="../../../training/multiscreen/screendensities.html" zh-cn-lang="支持各种屏幕密度" ja-lang="さまざまな画面密度のサポート" es-lang="Cómo admitir varias densidades de pantalla" >Supporting Different Screen Densities</a> </li> <li><a href="../../../training/multiscreen/adaptui.html" zh-cn-lang="实施自适应用户界面流程" ja-lang="順応性のある UI フローの実装" es-lang="Cómo implementar interfaces de usuario adaptables" >Implementing Adaptive UI Flows</a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/appbar/index.html" description= "How to use the support library's toolbar widget to implement an app bar that displays properly on a wide range of devices." >Adding the App Bar</a> </div> <ul> <li><a href="../../../training/appbar/setting-up.html" >Setting Up the App Bar</a> </li> <li><a href="../../../training/appbar/actions.html" >Adding and Handling Actions</a> </li> <li><a href="../../../training/appbar/up-action.html" >Adding an Up Action</a> </li> <li><a href="../../../training/appbar/action-views.html" >Action Views and Action Providers</a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/snackbar/index.html" description= "How to use the support library's Snackbar widget to display a brief pop-up message." >Showing Pop-Up Messages</a> </div> <ul> <li><a href="../../../training/snackbar/showing.html" >Building and Displaying a Pop-Up Message</a> </li> <li><a href="../../../training/snackbar/action.html" >Adding an Action to a Message</a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/custom-views/index.html" description= "How to build custom UI widgets that are interactive and smooth." >Creating Custom Views</a> </div> <ul> <li><a href="../../../training/custom-views/create-view.html"> Creating a Custom View Class </a> </li> <li><a href="../../../training/custom-views/custom-drawing.html"> Implementing Custom Drawing </a> </li> <li><a href="../../../training/custom-views/making-interactive.html"> Making the View Interactive </a> </li> <li><a href="../../../training/custom-views/optimizing-view.html"> Optimizing the View </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/backward-compatible-ui/index.html" description= "How to use UI components and other APIs from the more recent versions of Android while remaining compatible with older versions of the platform." >Creating Backward-Compatible UIs</a> </div> <ul> <li><a href="../../../training/backward-compatible-ui/abstracting.html"> Abstracting the New APIs </a> </li> <li><a href="../../../training/backward-compatible-ui/new-implementation.html"> Proxying to the New APIs </a> </li> <li><a href="../../../training/backward-compatible-ui/older-implementation.html"> Creating an Implementation with Older APIs </a> </li> <li><a href="../../../training/backward-compatible-ui/using-component.html"> Using the Version-Aware Component </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/accessibility/index.html" description= "How to make your app accessible to users with vision impairment or other physical disabilities." >Implementing Accessibility</a> </div> <ul> <li><a href="../../../training/accessibility/accessible-app.html"> Developing Accessible Applications </a> </li> <li><a href="../../../training/accessibility/service.html"> Developing Accessibility Services </a> </li> <li><a href="../../../training/accessibility/testing.html"> Accessibility Testing Checklist </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/system-ui/index.html" description= "How to hide and show status and navigation bars across different versions of Android, while managing the display of other screen components." >Managing the System UI</a> </div> <ul> <li><a href="../../../training/system-ui/dim.html"> Dimming the System Bars </a> </li> <li><a href="../../../training/system-ui/status.html"> Hiding the Status Bar </a> </li> <li><a href="../../../training/system-ui/navigation.html"> Hiding the Navigation Bar </a> </li> <li><a href="../../../training/system-ui/immersive.html"> Using Immersive Full-Screen Mode </a> </li> <li><a href="../../../training/system-ui/visibility.html"> Responding to UI Visibility Changes </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/material/index.html" description= "How to implement material design on Android." zh-cn-lang="面向开发者的材料设计" zh-tw-lang="開發人員材料設計" ja-lang="マテリアル デザインでのアプリ作成" es-lang="Crear aplicaciones con Material Design" pt-br-lang="Material Design para desenvolvedores" ko-lang="개발자를 위한 머티리얼 디자인" ru-lang="Создание приложений с помощью Material Design" in-lang="Desain Bahan untuk Pengembang" vi-lang="Material Design cho Nhà phát triển" >Creating Apps with Material Design</a> </div> <ul> <li><a href="../../../training/material/get-started.html" zh-cn-lang="入门指南" zh-tw-lang="開始使用" ja-lang="スタート ガイド" es-lang="Comencemos" pt-br-lang="Como iniciar" ko-lang="시작하기" ru-lang="Начало работы" in-lang="Memulai" vi-lang="Bắt đầu" > Getting Started </a> </li> <li><a href="../../../training/material/theme.html" zh-cn-lang="使用材料主题" zh-tw-lang="使用材料設計風格" ja-lang="マテリアル テーマの使用" es-lang="Usar el tema Material" pt-br-lang="Como usar o tema do Material" ko-lang="머티어리얼 테마 사용" ru-lang="Использование темы Material Design" in-lang="Menggunakan Tema Bahan" vi-lang="Sử dụng Chủ đề Material" > Using the Material Theme </a> </li> <li><a href="../../../training/material/lists-cards.html" zh-cn-lang="创建列表与卡片" zh-tw-lang="建立清單和卡片" ja-lang="リストとカードの作成" es-lang="Crear listas y tarjetas" pt-br-lang="Como criar listas e cartões" ko-lang="목록 및 카드 생성" ru-lang="Создание списков и подсказок" in-lang="Membuat Daftar dan Kartu" vi-lang="Tạo Danh sách và Thẻ" > Creating Lists and Cards </a> </li> <li><a href="../../../training/material/shadows-clipping.html" zh-cn-lang="定义阴影与裁剪视图" zh-tw-lang="定義陰影和裁剪檢視" ja-lang="シャドウとクリッピング ビューの定義" es-lang="Definir vistas de recorte y sombras" pt-br-lang="Como definir sombras e recortar visualizações" ko-lang="그림자 정의 및 뷰 클리핑" ru-lang="Определение теней и обрезка представлений" in-lang="Mendefinisikan Bayangan dan Memangkas Tampilan" vi-lang="Định nghĩa Đổ bóng và Dạng xem Cắt hình" > Defining Shadows and Clipping Views </a> </li> <li><a href="../../../training/material/drawables.html" zh-cn-lang="使用 Drawables" zh-tw-lang="使用可繪項目" ja-lang="ドローアブルの使用" es-lang="Trabajar con interfaces dibujables" pt-br-lang="Como trabalhar com desenháveis" ko-lang="Drawable 사용" ru-lang="Работа с элементами дизайна" in-lang="Bekerja dengan Drawable" vi-lang="Làm việc với Nội dung vẽ được" > Working with Drawables </a> </li> <li><a href="../../../training/material/animations.html" zh-cn-lang="定义定制动画" zh-tw-lang="定義自訂動畫" ja-lang="カスタム アニメーションの定義" es-lang="Definir animaciones personalizadas" pt-br-lang="Como definir animações personalizadas" ko-lang="사용자지정 애니메이션 정의" ru-lang="Определение настраиваемой анимации" in-lang="Mendefinisikan Animasi Custom" vi-lang="Định nghĩa Hoạt hình Tùy chỉnh" > Defining Custom Animations </a> </li> <li><a href="../../../training/material/compatibility.html" zh-cn-lang="维护兼容性" zh-tw-lang="維持相容性" ja-lang="互換性の維持" es-lang="Mantener la compatibilidad" pt-br-lang="Como manter a compatibilidade" ko-lang="호환성 유지" ru-lang="Обеспечение совместимости" in-lang="Mempertahankan Kompatibilitas" vi-lang="Duy trì Tính tương thích" > Maintaining Compatibility </a> </li> </ul> </li> </ul> </li> <!-- End User Interface --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/best-user-input.html"> <span class="small">Best Practices for</span><br/> User Input </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/gestures/index.html" description= "How to write apps that allow users to interact with the touch screen via touch gestures." >Using Touch Gestures</a> </div> <ul> <li><a href="../../../training/gestures/detector.html"> Detecting Common Gestures </a> </li> <li><a href="../../../training/gestures/movement.html"> Tracking Movement </a> </li> <li><a href="../../../training/gestures/scroll.html"> Animating a Scroll Gesture </a> </li> <li><a href="../../../training/gestures/multi.html"> Handling Multi-Touch Gestures </a> </li> <li><a href="../../../training/gestures/scale.html"> Dragging and Scaling </a> </li> <li><a href="../../../training/gestures/viewgroup.html"> Managing Touch Events in a ViewGroup </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/keyboard-input/index.html" description= "How to specify the appearance and behaviors of soft input methods (such as on-screen keyboards) and how to optimize the experience with hardware keyboards." >Handling Keyboard Input</a> </div> <ul> <li><a href="../../../training/keyboard-input/style.html"> Specifying the Input Method Type </a> </li> <li><a href="../../../training/keyboard-input/visibility.html"> Handling Input Method Visibility </a> </li> <li><a href="../../../training/keyboard-input/navigation.html"> Supporting Keyboard Navigation </a> </li> <li><a href="../../../training/keyboard-input/commands.html"> Handling Keyboard Actions </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/game-controllers/index.html" description= "How to write apps that support game controllers." >Supporting Game Controllers</a> </div> <ul> <li><a href="../../../training/game-controllers/controller-input.html"> Handling Controller Actions </a> </li> <li><a href="../../../training/game-controllers/compatibility.html"> Supporting Controllers Across Android Versions </a> </li> <li><a href="../../../training/game-controllers/multiple-controllers.html"> Supporting Multiple Game Controllers </a> </li> </ul> </li> </ul> </li> <!-- end of User Input --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/best-background.html"> <span class="small">Best Practices for</span><br/> Background Jobs </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/run-background-service/index.html" description= "How to improve UI performance and responsiveness by sending work to a Service running in the background" >Running in a Background Service</a> </div> <ul> <li><a href="../../../training/run-background-service/create-service.html"> Creating a Background Service </a> </li> <li><a href="../../../training/run-background-service/send-request.html"> Sending Work Requests to the Background Service </a> </li> <li><a href="../../../training/run-background-service/report-status.html"> Reporting Work Status </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/load-data-background/index.html" description="How to use CursorLoader to query data without affecting UI responsiveness." >Loading Data in the Background</a> </div> <ul> <li><a href="../../../training/load-data-background/setup-loader.html"> Running a Query with a CursorLoader</a> </li> <li><a href="../../../training/load-data-background/handle-results.html"> Handling the Results</a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/scheduling/index.html" description="How to use repeating alarms and wake locks to run background jobs." >Managing Device Awake State</a> </div> <ul> <li><a href="../../../training/scheduling/wakelock.html"> Keeping the Device Awake</a> </li> <li><a href="../../../training/scheduling/alarms.html"> Scheduling Repeating Alarms</a> </li> </ul> </li> </ul> </li> <!-- end of Background Jobs --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/best-performance.html"> <span class="small">Best Practices for</span><br/> Performance </a> </div> <ul> <li> <a href="../../../training/articles/memory.html" description= "How to keep your app's memory footprint small in order to improve performance on a variety of mobile devices." >Managing Your App's Memory</a> </li> <li> <a href="../../../training/articles/perf-tips.html" description= "How to optimize your app's performance in various ways to improve its responsiveness and battery efficiency." >Performance Tips</a> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/improving-layouts/index.html" description= "How to identify problems in your app's layout performance and improve the UI responsiveness." >Improving Layout Performance</a> </div> <ul> <li><a href="../../../training/improving-layouts/optimizing-layout.html"> Optimizing Layout Hierarchies </a> </li> <li><a href="../../../training/improving-layouts/reusing-layouts.html"> Re-using Layouts with <include/> </a> </li> <li><a href="../../../training/improving-layouts/loading-ondemand.html"> Loading Views On Demand </a> </li> <li><a href="../../../training/improving-layouts/smooth-scrolling.html"> Making ListView Scrolling Smooth </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/monitoring-device-state/index.html" zh-cn-lang="优化电池使用时间" ja-lang="電池消費量の最適化" es-lang="Cómo optimizar la duración de la batería" description= "How to minimize the amount of power your app requires by adapting to current power conditions and performing power-hungry tasks at proper intervals." >Optimizing Battery Life </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/performance/battery/network/index.html"> Reducing Network Battery Drain </a> </div> <ul> <li><a href="../../../training/performance/battery/network/gather-data.html"> Collecting Network Traffic Data </a> </li> <li><a href="../../../training/performance/battery/network/analyze-data.html"> Analyzing Network Traffic Data </a> </li> <li><a href="../../../training/performance/battery/network/action-user-traffic.html"> Optimizing User-Initiated Network Use </a> </li> <li><a href="../../../training/performance/battery/network/action-app-traffic.html"> Optimizing App-Initiated Network Use </a> </li> <li><a href="../../../training/performance/battery/network/action-server-traffic.html"> Optimizing Server-Initiated Network Use </a> </li> <li><a href="../../../training/performance/battery/network/action-any-traffic.html"> Optimizing General Network Use </a> </li> </ul> </li> <!-- End of Reducing Network Battery Drain --> <li><a href="../../../training/monitoring-device-state/doze-standby.html" >Optimizing for Doze and App Standby</a> </li> <li><a href="../../../training/monitoring-device-state/battery-monitoring.html" zh-cn-lang="监控电池电量和充电状态" ja-lang="電池残量と充電状態の監視" es-lang="Cómo controlar el nivel de batería y el estado de carga" >Monitoring the Battery Level and Charging State</a> </li> <li><a href="../../../training/monitoring-device-state/docking-monitoring.html" zh-cn-lang="确定和监控基座对接状态和类型" ja-lang="ホルダーの装着状態とタイプの特定と監視" es-lang="Cómo determinar y controlar el tipo de conector y el estado de la conexión" >Determining and Monitoring the Docking State and Type</a> </li> <li><a href="../../../training/monitoring-device-state/connectivity-monitoring.html" zh-cn-lang="确定和监控网络连接状态" ja-lang="接続状態の特定と監視" es-lang="Cómo determinar y controlar el estado de la conectividad" >Determining and Monitoring the Connectivity Status</a> </li> <li><a href="../../../training/monitoring-device-state/manifest-receivers.html" zh-cn-lang="根据需要操作广播接收器" ja-lang="オンデマンドでのブロードキャスト レシーバ操作" es-lang="Cómo manipular los receptores de emisión bajo demanda" >Manipulating Broadcast Receivers On Demand</a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/multiple-threads/index.html" description= "How to improve the performance and scalability of long-running operations by dispatching work to multiple threads."> Sending Operations to Multiple Threads</a> </div> <ul> <li><a href="../../../training/multiple-threads/define-runnable.html"> Specifying the Code to Run on a Thread </a> </li> <li><a href="../../../training/multiple-threads/create-threadpool.html"> Creating a Manager for Multiple Threads </a> </li> <li><a href="../../../training/multiple-threads/run-code.html"> Running Code on a Thread Pool Thread </a> </li> <li><a href="../../../training/multiple-threads/communicate-ui.html"> Communicating with the UI Thread </a> </li> </ul> </li> <li> <a href="../../../training/articles/perf-anr.html" description= "How to keep your app responsive to user interaction so the UI does not lock-up and display an "Application Not Responding" dialog." >Keeping Your App Responsive</a> </li> <li> <a href="../../../training/articles/perf-jni.html" description= "How to efficiently use the Java Native Interface with the Android NDK." >JNI Tips</a> </li> <li> <a href="../../../training/articles/smp.html" description= "Tips for coding Android apps on symmetric multiprocessor systems." >SMP Primer for Android</a> </li> </ul> </li> <!-- end of Performance --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/best-security.html"> <span class="small">Best Practices for</span><br/> Security & Privacy </a> </div> <ul> <li> <a href="../../../training/articles/security-tips.html" description= "How to perform various tasks and keep your app's data and your user's data secure." >Security Tips</a> </li> <li> <a href="../../../training/articles/security-ssl.html" description= "How to ensure that your app is secure when performing network transactions." >Security with HTTPS and SSL</a> </li> <li> <a href="../../../training/articles/security-gms-provider.html" description= "How to use and update Google Play services security provider, to protect against SSL exploits." >Updating Your Security Provider to Protect Against SSL Exploits</a> </li> <li> <a href="../../../training/safetynet/index.html" description= "How to use the SafetyNet service to analyze a device where your app is running and get information about its compatibility with your app." >Checking Device Compatibility with SafetyNet</a> </li> <li> <a href="../../../work/device-management-policy.html" description="How to create an application that enforces security policies on devices." >Enhancing Security with Device Management Policies</a> </li> </ul> </li> <!-- End security and user info --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/best-permissions-ids.html"> <span class="small">Best Practices for</span><br/> Permissions & Identifiers </a> </div> <ul> <li> <a href="../../../training/articles/user-data-overview.html" description= "Overview of app permissions on Android and how they affect your users." >Permissions and User Data</a> </li> <li> <a href="../../../training/articles/user-data-permissions.html" description= "How to manage permissions the right way for users." >Best Practices for App Permissions</a> </li> <li> <a href="../../../training/articles/user-data-ids.html" description= "Unique identifiers available and how to choose the right one for your use case." >Best Practices for Unique Identifiers</a> </li> </ul> </li> <!-- End Permissions and identifiers --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/testing/index.html"> <span class="small">Best Practices for</span><br/> Testing </a> </div> <ul> <li> <a href="../../../training/testing/start/index.html" description="How to get started with testing your Android applications."> Getting Started with Testing </a> </li> <li class="nav-section"> <div class="nav-section-header"><a href="../../../training/testing/unit-testing/index.html" description="How to build effective unit tests for Android apps."> Building Effective Unit Tests </a></div> <ul> <li><a href="../../../training/testing/unit-testing/local-unit-tests.html"> <span class="en">Building Local Unit Tests</span> </a> </li> <li><a href="../../../training/testing/unit-testing/instrumented-unit-tests.html"> <span class="en">Building Instrumented Unit Tests</span> </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"><a href="../../../training/testing/ui-testing/index.html" description="How to automate your user interface tests for Android apps."> Automating UI Tests </a></div> <ul> <li><a href="../../../training/testing/ui-testing/espresso-testing.html"> <span class="en">Testing UI for a Single App</span> </a> </li> <li><a href="../../../training/testing/ui-testing/uiautomator-testing.html"> <span class="en">Testing UI for Multiple Apps</span> </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"><a href="../../../training/testing/integration-testing/index.html" description="How to build effective integration tests for Android apps."> Testing App Component Integrations </a></div> <ul> <li><a href="../../../training/testing/integration-testing/service-testing.html"> <span class="en">Testing Your Service</span></a></li> <li><a href="../../../training/testing/integration-testing/content-provider-testing.html"> <span class="en">Testing Your Content Provider</span></a></li> </ul> </li> <li><a href="../../../training/testing/performance.html" description="How to automate UI performance testing.">Testing Display Performance</a> </li> </ul> </li> <!-- End best Testing --> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/distribute.html"> <span class="small">Using Google Play to</span><br/> Distribute & Monetize </a> </div> <ul> <li class="nav-section"> <div class="nav-section-header"><a href="../../../training/in-app-billing/index.html" description="How to sell in-app products from your application using In-app Billing."> Selling In-app Products </a></div> <ul> <li><a href="../../../training/in-app-billing/preparing-iab-app.html"> <span class="en">Preparing Your App</span> </a> </li> <li><a href="../../../training/in-app-billing/list-iab-products.html"> <span class="en">Establishing Products for Sale</span> </a> </li> <li><a href="../../../training/in-app-billing/purchase-iab-products.html"> <span class="en">Purchasing Products</span> </a> </li> <li><a href="../../../training/in-app-billing/test-iab-app.html"> <span class="en">Testing Your App</span> </a> </li> </ul> </li> <li class="nav-section"> <div class="nav-section-header"> <a href="../../../training/multiple-apks/index.html" description= "How to publish your app on Google Play with separate APKs that target different devices, while using a single app listing." >Maintaining Multiple APKs</a> </div> <ul> <li><a href="../../../training/multiple-apks/api.html"> Creating Multiple APKs for Different API Levels </a> </li> <li><a href="../../../training/multiple-apks/screensize.html"> Creating Multiple APKs for Different Screen Sizes </a> </li> <li><a href="../../../training/multiple-apks/texture.html"> Creating Multiple APKs for Different GL Textures </a> </li> <li><a href="../../../training/multiple-apks/multiple.html"> Creating Multiple APKs with 2+ Dimensions </a> </li> </ul> </li> </ul> </li> <!-- End best Publishing --> </ul><!-- nav --> <script type="text/javascript"> <!-- buildToggleLists(); changeNavLang(getLangPref()); //--> </script> </div> <ul id="dac-main-navigation" class="dac-nav-list dac-swap-section dac-left dac-no-anim"> <li class="dac-nav-item home"> <a class="dac-nav-link" href="../../../index.html">Home</a> <i class="dac-sprite dac-expand-more-black dac-nav-sub-slider"></i> <ul class="dac-nav-secondary about"> <li class="dac-nav-item versions"> <a class="dac-nav-link" href="../../../about/versions/marshmallow/index.html">Android</a> </li> <li class="dac-nav-item wear"> <a class="dac-nav-link" href="../../../wear/index.html">Wear</a> </li> <li class="dac-nav-item tv"> <a class="dac-nav-link" href="../../../tv/index.html">TV</a> </li> <li class="dac-nav-item auto"> <a class="dac-nav-link" href="../../../auto/index.html">Auto</a> </li> </ul> </li> <li class="dac-nav-item design"> <a class="dac-nav-link" href="../../../design/index.html" zh-tw-lang="設計" zh-cn-lang="设计" ru-lang="Проектирование" ko-lang="디자인" ja-lang="設計" es-lang="Diseñar">Design</a> </li> <li class="dac-nav-item develop"> <a class="dac-nav-link" href="../../../develop/index.html" zh-tw-lang="開發" zh-cn-lang="开发" ru-lang="Разработка" ko-lang="개발" ja-lang="開発" es-lang="Desarrollar">Develop</a> <i class="dac-sprite dac-expand-more-black dac-nav-sub-slider"></i> <ul class="dac-nav-secondary develop"> <li class="dac-nav-item training"> <a class="dac-nav-link" href="../../../training/index.html" zh-tw-lang="訓練課程" zh-cn-lang="培训" ru-lang="Курсы" ko-lang="교육" ja-lang="トレーニング" es-lang="Capacitación">Training</a> </li> <li class="dac-nav-item guide"> <a class="dac-nav-link" href="../../../guide/index.html" zh-tw-lang="API 指南" zh-cn-lang="API 指南" ru-lang="Руководства по API" ko-lang="API 가이드" ja-lang="API ガイド" es-lang="Guías de la API">API Guides</a> </li> <li class="dac-nav-item reference"> <a class="dac-nav-link" href="../../../reference/packages.html" zh-tw-lang="參考資源" zh-cn-lang="参考" ru-lang="Справочник" ko-lang="참조문서" ja-lang="リファレンス" es-lang="Referencia">Reference</a> </li> <li class="dac-nav-item tools"> <a class="dac-nav-link" href="../../../sdk/index.html" zh-tw-lang="相關工具" zh-cn-lang="工具" ru-lang="Инструменты" ko-lang="도구" ja-lang="ツール" es-lang="Herramientas">Tools</a></li> <li class="dac-nav-item google"> <a class="dac-nav-link" href="../../../google/index.html">Google Services</a> </li> </ul> </li> <li class="dac-nav-item distribute"> <a class="dac-nav-link" href="../../../distribute/googleplay/index.html" zh-tw-lang="發佈" zh-cn-lang="分发" ru-lang="Распространение" ko-lang="배포" ja-lang="配布" es-lang="Distribuir">Distribute</a> <i class="dac-sprite dac-expand-more-black dac-nav-sub-slider"></i> <ul class="dac-nav-secondary distribute"> <li class="dac-nav-item googleplay"> <a class="dac-nav-link" href="../../../distribute/googleplay/index.html">Google Play</a></li> <li class="dac-nav-item essentials"> <a class="dac-nav-link" href="../../../distribute/essentials/index.html">Essentials</a></li> <li class="dac-nav-item users"> <a class="dac-nav-link" href="../../../distribute/users/index.html">Get Users</a></li> <li class="dac-nav-item engage"> <a class="dac-nav-link" href="../../../distribute/engage/index.html">Engage & Retain</a></li> <li class="dac-nav-item monetize"> <a class="dac-nav-link" href="../../../distribute/monetize/index.html">Earn</a> </li> <li class="dac-nav-item analyze"> <a class="dac-nav-link" href="../../../distribute/analyze/index.html">Analyze</a> </li> <li class="dac-nav-item stories"> <a class="dac-nav-link" href="../../../distribute/stories/index.html">Stories</a> </li> </ul> </li> <li class="dac-nav-item preview"> <a class="dac-nav-link" href="../../../preview/index.html">Preview</a> </li> </ul> </div> </div> </nav> <!-- end navigation--> <!-- Nav Setup --> <script>$('[data-dac-nav]').dacNav();</script> <div class="wrap clearfix" id="body-content"> <div id="search-results" class="dac-search-results"> <div id="dac-search-results-history" class="dac-search-results-history"> <div class="wrap dac-search-results-history-wrap"> <div class="cols"> <div class="col-1of2 col-tablet-1of2 col-mobile-1of1"> <h2>Most visited</h2> <div class="resource-flow-layout" data-history-query="history:most/visited" data-maxresults="3" data-cardsizes="18x2"></div> </div> <div class="col-1of2 col-tablet-1of2 col-mobile-1of1"> <h2>Recently visited</h2> <div class="resource-flow-layout cols" data-history-query="history:recent" data-allow-duplicates="true" data-maxresults="3" data-cardsizes="18x2"></div> </div> </div> </div> </div> <div id="dac-search-results-content" class="dac-search-results-content"> <div class="dac-search-results-metadata wrap"> <div class="dac-search-results-for"> <h2>Results for <span id="search-results-for"></span></h2> </div> <div id="dac-search-results-hero"></div> <div class="dac-search-results-hero cols"> <div id="dac-search-results-reference" class="col-3of6 col-tablet-1of2 col-mobile-1of1"> <div class="suggest-card reference no-display"> <ul class="dac-search-results-reference"> </ul> </div> </div> <div id="dac-custom-search-results"></div> </div> </div> </div> </div> <div class="content-header "> <ul class="dac-header-crumbs"> </ul> <!-- Breadcrumb Setup --> <script>$('.dac-nav-list').dacCurrentPage().dacCrumbs();</script> <h1 itemprop="name">Saving Files </h1> <div class="training-nav-top" itemscope itemtype="http://schema.org/SiteNavigationElement"> <a href="#" class="prev-page-link hide" zh-tw-lang="上一堂課" zh-cn-lang="上一课" ru-lang="Предыдущий" ko-lang="이전" ja-lang="前へ" es-lang="Anterior" >Previous</a> <a href="#" class="next-page-link hide" zh-tw-lang="下一堂課" zh-cn-lang="下一课" ru-lang="Следующий" ko-lang="다음" ja-lang="次へ" es-lang="Siguiente" >Next</a> <a href="#" class="start-class-link hide" zh-tw-lang="開始上課" zh-cn-lang="开始" ru-lang="Начало работы" ko-lang="시작하기" ja-lang="開始する" es-lang="Empezar" >Get started</a> </div> </div> <div id="jd-content"> <div class="jd-descr" itemprop="articleBody"> <div id="tb-wrapper"> <div id="tb"> <h2>This lesson teaches you to</h2> <ol> <li><a href="#InternalVsExternalStorage">Choose Internal or External Storage</a></li> <li><a href="#GetWritePermission">Obtain Permissions for External Storage</a></li> <li><a href="#WriteInternalStorage">Save a File on Internal Storage</a></li> <li><a href="#WriteExternalStorage">Save a File on External Storage</a></li> <li><a href="#GetFreeSpace">Query Free Space</a></li> <li><a href="#DeleteFile">Delete a File</a></li> </ol> <h2>You should also read</h2> <ul> <li><a href="../../../guide/topics/data/data-storage.html#filesInternal">Using the Internal Storage</a></li> <li><a href="../../../guide/topics/data/data-storage.html#filesExternal">Using the External Storage</a></li> </ul> </div> </div> <p>Android uses a file system that's similar to disk-based file systems on other platforms. This lesson describes how to work with the Android file system to read and write files with the <code><a href="../../../reference/java/io/File.html">File</a></code> APIs.</p> <p>A <code><a href="../../../reference/java/io/File.html">File</a></code> object is suited to reading or writing large amounts of data in start-to-finish order without skipping around. For example, it's good for image files or anything exchanged over a network.</p> <p>This lesson shows how to perform basic file-related tasks in your app. The lesson assumes that you are familiar with the basics of the Linux file system and the standard file input/output APIs in <code><a href="../../../reference/java/io/package-summary.html">java.io</a></code>.</p> <h2 id="InternalVsExternalStorage">Choose Internal or External Storage</h2> <p>All Android devices have two file storage areas: "internal" and "external" storage. These names come from the early days of Android, when most devices offered built-in non-volatile memory (internal storage), plus a removable storage medium such as a micro SD card (external storage). Some devices divide the permanent storage space into "internal" and "external" partitions, so even without a removable storage medium, there are always two storage spaces and the API behavior is the same whether the external storage is removable or not. The following lists summarize the facts about each storage space.</p> <div class="col-5" style="margin-left:0"> <p><b>Internal storage:</b></p> <ul> <li>It's always available.</li> <li>Files saved here are accessible by only your app.</li> <li>When the user uninstalls your app, the system removes all your app's files from internal storage.</li> </ul> <p>Internal storage is best when you want to be sure that neither the user nor other apps can access your files.</p> </div> <div class="col-7" style="margin-right:0"> <p><b>External storage:</b></p> <ul> <li>It's not always available, because the user can mount the external storage as USB storage and in some cases remove it from the device.</li> <li>It's world-readable, so files saved here may be read outside of your control.</li> <li>When the user uninstalls your app, the system removes your app's files from here only if you save them in the directory from <code><a href="../../../reference/android/content/Context.html#getExternalFilesDir(java.lang.String)">getExternalFilesDir()</a></code>.</li> </ul> <p>External storage is the best place for files that don't require access restrictions and for files that you want to share with other apps or allow the user to access with a computer.</p> </div> <p class="note"> <strong>Note:</strong> Before Android N, internal files could be made accessible to other apps by means of relaxing file system permissions. This is no longer the case. If you wish to make the content of a private file accessible to other apps, your app may use the <code><a href="../../../reference/android/support/v4/content/FileProvider.html">FileProvider</a></code>. See <a href="../../../training/secure-file-sharing/index.html">Sharing Files</a>.</p> <p class="note" style="clear:both"> <strong>Tip:</strong> Although apps are installed onto the internal storage by default, you can specify the <a href="../../../guide/topics/manifest/manifest-element.html#install"><code>android:installLocation</code></a> attribute in your manifest so your app may be installed on external storage. Users appreciate this option when the APK size is very large and they have an external storage space that's larger than the internal storage. For more information, see <a href="../../../guide/topics/data/install-location.html">App Install Location</a>.</p> <h2 id="GetWritePermission">Obtain Permissions for External Storage</h2> <p>To write to the external storage, you must request the <code><a href="../../../reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE">WRITE_EXTERNAL_STORAGE</a></code> permission in your <a href="../../../guide/topics/manifest/manifest-intro.html">manifest file</a>:</p> <pre> <manifest ...> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> ... </manifest> </pre> <div class="caution"><p><strong>Caution:</strong> Currently, all apps have the ability to read the external storage without a special permission. However, this will change in a future release. If your app needs to read the external storage (but not write to it), then you will need to declare the <code><a href="../../../reference/android/Manifest.permission.html#READ_EXTERNAL_STORAGE">READ_EXTERNAL_STORAGE</a></code> permission. To ensure that your app continues to work as expected, you should declare this permission now, before the change takes effect.</p> <pre> <manifest ...> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> ... </manifest> </pre> <p>However, if your app uses the <code><a href="../../../reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE">WRITE_EXTERNAL_STORAGE</a></code> permission, then it implicitly has permission to read the external storage as well.</p> </div> <p>You don’t need any permissions to save files on the internal storage. Your application always has permission to read and write files in its internal storage directory.</p> <h2 id="WriteInternalStorage">Save a File on Internal Storage</h2> <p>When saving a file to internal storage, you can acquire the appropriate directory as a <code><a href="../../../reference/java/io/File.html">File</a></code> by calling one of two methods:</p> <dl> <dt><code><a href="../../../reference/android/content/Context.html#getFilesDir()">getFilesDir()</a></code></dt> <dd>Returns a <code><a href="../../../reference/java/io/File.html">File</a></code> representing an internal directory for your app.</dd> <dt><code><a href="../../../reference/android/content/Context.html#getCacheDir()">getCacheDir()</a></code></dt> <dd>Returns a <code><a href="../../../reference/java/io/File.html">File</a></code> representing an internal directory for your app's temporary cache files. Be sure to delete each file once it is no longer needed and implement a reasonable size limit for the amount of memory you use at any given time, such as 1MB. If the system begins running low on storage, it may delete your cache files without warning.</dd> </dl> <p>To create a new file in one of these directories, you can use the <code><a href="../../../reference/java/io/File.html#File(java.io.File, java.lang.String)">File()</a></code> constructor, passing the <code><a href="../../../reference/java/io/File.html">File</a></code> provided by one of the above methods that specifies your internal storage directory. For example:</p> <pre> File file = new File(context.getFilesDir(), filename); </pre> <p>Alternatively, you can call <code><a href="../../../reference/android/content/Context.html#openFileOutput(java.lang.String, int)">openFileOutput()</a></code> to get a <code><a href="../../../reference/java/io/FileOutputStream.html">FileOutputStream</a></code> that writes to a file in your internal directory. For example, here's how to write some text to a file:</p> <pre> String filename = "myfile"; String string = "Hello world!"; FileOutputStream outputStream; try { outputStream = openFileOutput(filename, Context.MODE_PRIVATE); outputStream.write(string.getBytes()); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } </pre> <p>Or, if you need to cache some files, you should instead use <code><a href="../../../reference/java/io/File.html#createTempFile(java.lang.String, java.lang.String)">createTempFile()</a></code>. For example, the following method extracts the file name from a <code><a href="../../../reference/java/net/URL.html">URL</a></code> and creates a file with that name in your app's internal cache directory:</p> <pre> public File getTempFile(Context context, String url) { File file; try { String fileName = Uri.parse(url).getLastPathSegment(); file = File.createTempFile(fileName, null, context.getCacheDir()); } catch (IOException e) { // Error while creating file } return file; } </pre> <p class="note"><strong>Note:</strong> Your app's internal storage directory is specified by your app's package name in a special location of the Android file system. Technically, another app can read your internal files if you set the file mode to be readable. However, the other app would also need to know your app package name and file names. Other apps cannot browse your internal directories and do not have read or write access unless you explicitly set the files to be readable or writable. So as long as you use <code><a href="../../../reference/android/content/Context.html#MODE_PRIVATE">MODE_PRIVATE</a></code> for your files on the internal storage, they are never accessible to other apps.</p> <h2 id="WriteExternalStorage">Save a File on External Storage</h2> <p>Because the external storage may be unavailable—such as when the user has mounted the storage to a PC or has removed the SD card that provides the external storage—you should always verify that the volume is available before accessing it. You can query the external storage state by calling <code><a href="../../../reference/android/os/Environment.html#getExternalStorageState()">getExternalStorageState()</a></code>. If the returned state is equal to <code><a href="../../../reference/android/os/Environment.html#MEDIA_MOUNTED">MEDIA_MOUNTED</a></code>, then you can read and write your files. For example, the following methods are useful to determine the storage availability:</p> <pre> /* Checks if external storage is available for read and write */ public boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; } /* Checks if external storage is available to at least read */ public boolean isExternalStorageReadable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { return true; } return false; } </pre> <p>Although the external storage is modifiable by the user and other apps, there are two categories of files you might save here:</p> <dl> <dt>Public files</dt> <dd>Files that should be freely available to other apps and to the user. When the user uninstalls your app, these files should remain available to the user. <p>For example, photos captured by your app or other downloaded files.</p> </dd> <dt>Private files</dt> <dd>Files that rightfully belong to your app and should be deleted when the user uninstalls your app. Although these files are technically accessible by the user and other apps because they are on the external storage, they are files that realistically don't provide value to the user outside your app. When the user uninstalls your app, the system deletes all files in your app's external private directory. <p>For example, additional resources downloaded by your app or temporary media files.</p> </dd> </dl> <p>If you want to save public files on the external storage, use the <code><a href="../../../reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)">getExternalStoragePublicDirectory()</a></code> method to get a <code><a href="../../../reference/java/io/File.html">File</a></code> representing the appropriate directory on the external storage. The method takes an argument specifying the type of file you want to save so that they can be logically organized with other public files, such as <code><a href="../../../reference/android/os/Environment.html#DIRECTORY_MUSIC">DIRECTORY_MUSIC</a></code> or <code><a href="../../../reference/android/os/Environment.html#DIRECTORY_PICTURES">DIRECTORY_PICTURES</a></code>. For example:</p> <pre> public File getAlbumStorageDir(String albumName) { // Get the directory for the user's public pictures directory. File file = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), albumName); if (!file.mkdirs()) { Log.e(LOG_TAG, "Directory not created"); } return file; } </pre> <p>If you want to save files that are private to your app, you can acquire the appropriate directory by calling <code><a href="../../../reference/android/content/Context.html#getExternalFilesDir(java.lang.String)">getExternalFilesDir()</a></code> and passing it a name indicating the type of directory you'd like. Each directory created this way is added to a parent directory that encapsulates all your app's external storage files, which the system deletes when the user uninstalls your app.</p> <p>For example, here's a method you can use to create a directory for an individual photo album:</p> <pre> public File getAlbumStorageDir(Context context, String albumName) { // Get the directory for the app's private pictures directory. File file = new File(context.getExternalFilesDir( Environment.DIRECTORY_PICTURES), albumName); if (!file.mkdirs()) { Log.e(LOG_TAG, "Directory not created"); } return file; } </pre> <p>If none of the pre-defined sub-directory names suit your files, you can instead call <code><a href="../../../reference/android/content/Context.html#getExternalFilesDir(java.lang.String)">getExternalFilesDir()</a></code> and pass <code>null</code>. This returns the root directory for your app's private directory on the external storage.</p> <p>Remember that <code><a href="../../../reference/android/content/Context.html#getExternalFilesDir(java.lang.String)">getExternalFilesDir()</a></code> creates a directory inside a directory that is deleted when the user uninstalls your app. If the files you're saving should remain available after the user uninstalls your app—such as when your app is a camera and the user will want to keep the photos—you should instead use <code><a href="../../../reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)">getExternalStoragePublicDirectory()</a></code>.</p> <p>Regardless of whether you use <code><a href="../../../reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)">getExternalStoragePublicDirectory()</a></code> for files that are shared or <code><a href="../../../reference/android/content/Context.html#getExternalFilesDir(java.lang.String)">getExternalFilesDir()</a></code> for files that are private to your app, it's important that you use directory names provided by API constants like <code><a href="../../../reference/android/os/Environment.html#DIRECTORY_PICTURES">DIRECTORY_PICTURES</a></code>. These directory names ensure that the files are treated properly by the system. For instance, files saved in <code><a href="../../../reference/android/os/Environment.html#DIRECTORY_RINGTONES">DIRECTORY_RINGTONES</a></code> are categorized by the system media scanner as ringtones instead of music.</p> <h2 id="GetFreeSpace">Query Free Space</h2> <p>If you know ahead of time how much data you're saving, you can find out whether sufficient space is available without causing an <code><a href="../../../reference/java/io/IOException.html">IOException</a></code> by calling <code><a href="../../../reference/java/io/File.html#getFreeSpace()">getFreeSpace()</a></code> or <code><a href="../../../reference/java/io/File.html#getTotalSpace()">getTotalSpace()</a></code>. These methods provide the current available space and the total space in the storage volume, respectively. This information is also useful to avoid filling the storage volume above a certain threshold.</p> <p>However, the system does not guarantee that you can write as many bytes as are indicated by <code><a href="../../../reference/java/io/File.html#getFreeSpace()">getFreeSpace()</a></code>. If the number returned is a few MB more than the size of the data you want to save, or if the file system is less than 90% full, then it's probably safe to proceed. Otherwise, you probably shouldn't write to storage.</p> <p class="note"><strong>Note:</strong> You aren't required to check the amount of available space before you save your file. You can instead try writing the file right away, then catch an <code><a href="../../../reference/java/io/IOException.html">IOException</a></code> if one occurs. You may need to do this if you don't know exactly how much space you need. For example, if you change the file's encoding before you save it by converting a PNG image to JPEG, you won't know the file's size beforehand.</p> <h2 id="DeleteFile">Delete a File</h2> <p>You should always delete files that you no longer need. The most straightforward way to delete a file is to have the opened file reference call <code><a href="../../../reference/java/io/File.html#delete()">delete()</a></code> on itself.</p> <pre> myFile.delete(); </pre> <p>If the file is saved on internal storage, you can also ask the <code><a href="../../../reference/android/content/Context.html">Context</a></code> to locate and delete a file by calling <code><a href="../../../reference/android/content/Context.html#deleteFile(java.lang.String)">deleteFile()</a></code>:</p> <pre> myContext.deleteFile(fileName); </pre> <div class="note"> <p><strong>Note:</strong> When the user uninstalls your app, the Android system deletes the following:</p> <ul> <li>All files you saved on internal storage</li> <li>All files you saved on external storage using <code><a href="../../../reference/android/content/Context.html#getExternalFilesDir(java.lang.String)">getExternalFilesDir()</a></code>.</li> </ul> <p>However, you should manually delete all cached files created with <code><a href="../../../reference/android/content/Context.html#getCacheDir()">getCacheDir()</a></code> on a regular basis and also regularly delete other files you no longer need.</p> </div> </div> <div class="content-footer " itemscope itemtype="http://schema.org/SiteNavigationElement"> <div class="paging-links"> <a href="#" class="prev-page-link hide" zh-tw-lang="上一堂課" zh-cn-lang="上一课" ru-lang="Предыдущий" ko-lang="이전" ja-lang="前へ" es-lang="Anterior" ><span class="page-link-caption">Previous</span> </a> <a href="#" class="next-page-link hide" zh-tw-lang="下一堂課" zh-cn-lang="下一课" ru-lang="Следующий" ko-lang="다음" ja-lang="次へ" es-lang="Siguiente" ><span class="page-link-caption">Next</span> </a> <a href="#" class="start-class-link hide" zh-tw-lang="開始上課" zh-cn-lang="开始" ru-lang="Начало работы" ko-lang="시작하기" ja-lang="開始する" es-lang="Empezar" >Get started</a> <a href="#" class="next-class-link hide"> <span class="page-link-caption">Next class</span> </a> </div> </div> </div> <!-- end jd-content --> <div class="wrap"> <div class="dac-footer"> <div class="cols dac-footer-main"> <div class="col-1of2"> <a class="dac-footer-getnews" id="newsletter" data-modal-toggle="newsletter" href="javascript:;">Get news & tips <span class="dac-fab dac-primary"><i class="dac-sprite dac-mail"></i></span></a> </div> <div class="col-1of2 dac-footer-reachout"> <div class="dac-footer-contact"> <a class="dac-footer-contact-link" href="http://android-developers.blogspot.com/">Blog</a> <a class="dac-footer-contact-link" href="/support.html">Support</a> </div> <div class="dac-footer-social"> <a class="dac-button-social dac-youtube dac-footer-social-link" href="https://www.youtube.com/user/androiddevelopers"><i class="dac-sprite dac-youtube"></i></a> <a class="dac-button-social dac-gplus dac-footer-social-link" href="https://plus.google.com/+AndroidDevelopers"><i class="dac-sprite dac-gplus"></i></a> <a class="dac-button-social dac-twitter dac-footer-social-link" href="https://twitter.com/AndroidDev"><i class="dac-sprite dac-twitter"></i></a> </div> </div> </div> <hr class="dac-footer-separator"/> <p class="dac-footer-copyright"> Except as noted, this content is licensed under <a href="http://creativecommons.org/licenses/by/2.5/"> Creative Commons Attribution 2.5</a>. For details and restrictions, see the <a href="../../../license.html">Content License</a>. </p> <p class="dac-footer-links"> <a href="/about/android.html">About Android</a> <a href="/auto/index.html">Auto</a> <a href="/tv/index.html">TV</a> <a href="/wear/index.html">Wear</a> <a href="/legal.html">Legal</a> <span id="language" class="locales"> <select name="language" onchange="changeLangPref(this.value, true)"> <option value="en" selected="selected">English</option> <option value="es">Español</option> <option value="in">Bahasa Indonesia</option> <option value="ja">日本語</option> <option value="ko">한국어</option> <option value="pt-br">Português Brasileiro</option> <option value="ru">Русский</option> <option value="vi">tiếng Việt</option> <option value="zh-cn">中文(简体)</option> <option value="zh-tw">中文(繁體)</option> </select> </span> </p> </div> </div> <!-- end footer --> <div data-modal="newsletter" data-newsletter data-swap class="dac-modal newsletter"> <div class="dac-modal-container"> <div class="dac-modal-window"> <header class="dac-modal-header"> <div class="dac-modal-header-actions"> <button class="dac-modal-header-close" data-modal-toggle></button> </div> <div class="dac-swap" data-swap-container> <section class="dac-swap-section dac-active dac-down"> <h2 class="norule dac-modal-header-title" data-t="newsletter.title"></h2> <p class="dac-modal-header-subtitle" data-t="newsletter.requiredHint"></p> </section> <section class="dac-swap-section dac-up"> <h2 class="norule dac-modal-header-title" data-t="newsletter.successTitle">Hooray!</h2> </section> </div> </header> <div class="dac-swap" data-swap-container> <section class="dac-swap-section dac-active dac-left"> <form action="https://docs.google.com/forms/d/1QgnkzbEJIDu9lMEea0mxqWrXUJu0oBCLD7ar23V0Yys/formResponse" class="dac-form" method="post" target="dac-newsletter-iframe"> <input type="hidden" name="entry.935454734" data-newsletter-language> <section class="dac-modal-content"> <fieldset class="dac-form-fieldset"> <div class="cols"> <div class="col-1of2 newsletter-leftCol"> <div class="dac-form-input-group"> <label for="newsletter-full-name" class="dac-form-floatlabel" data-t="newsletter.name">Full name</label> <input type="text" class="dac-form-input" name="entry.1357890476" id="newsletter-full-name" required> <span class="dac-form-required">*</span> </div> <div class="dac-form-input-group"> <label for="newsletter-email" class="dac-form-floatlabel" data-t="newsletter.email">Email address</label> <input type="email" class="dac-form-input" name="entry.472100832" id="newsletter-email" required> <span class="dac-form-required">*</span> </div> </div> <div class="col-1of2 newsletter-rightCol"> <div class="dac-form-input-group"> <label for="newsletter-company" class="dac-form-floatlabel" data-t="newsletter.company">Company / developer name</label> <input type="text" class="dac-form-input" name="entry.1664780309" id="newsletter-company"> </div> <div class="dac-form-input-group"> <label for="newsletter-play-store" class="dac-form-floatlabel" data-t="newsletter.appUrl">One of your Play Store app URLs</label> <input type="url" class="dac-form-input" name="entry.47013838" id="newsletter-play-store" required> <span class="dac-form-required">*</span> </div> </div> </div> </fieldset> <fieldset class="dac-form-fieldset"> <div class="cols"> <div class="col-1of2 newsletter-leftCol"> <legend class="dac-form-legend"><span data-t="newsletter.business.label">Which best describes your business:</span><span class="dac-form-required">*</span> </legend> <div class="dac-form-radio-group"> <input type="radio" value="Apps" class="dac-form-radio" name="entry.1796324055" id="newsletter-business-type-app" required> <label for="newsletter-business-type-app" class="dac-form-radio-button"></label> <label for="newsletter-business-type-app" class="dac-form-label" data-t="newsletter.business.apps">Apps</label> </div> <div class="dac-form-radio-group"> <input type="radio" value="Games" class="dac-form-radio" name="entry.1796324055" id="newsletter-business-type-games" required> <label for="newsletter-business-type-games" class="dac-form-radio-button"></label> <label for="newsletter-business-type-games" class="dac-form-label" data-t="newsletter.business.games">Games</label> </div> <div class="dac-form-radio-group"> <input type="radio" value="Apps and Games" class="dac-form-radio" name="entry.1796324055" id="newsletter-business-type-appsgames" required> <label for="newsletter-business-type-appsgames" class="dac-form-radio-button"></label> <label for="newsletter-business-type-appsgames" class="dac-form-label" data-t="newsletter.business.both">Apps & Games</label> </div> </div> <div class="col-1of2 newsletter-rightCol newsletter-checkboxes"> <div class="dac-form-radio-group"> <div class="dac-media"> <div class="dac-media-figure"> <input type="checkbox" class="dac-form-checkbox" name="entry.732309842" id="newsletter-add" required value="Add me to the mailing list for the monthly newsletter and occasional emails about development and Google Play opportunities."> <label for="newsletter-add" class="dac-form-checkbox-button"></label> </div> <div class="dac-media-body"> <label for="newsletter-add" class="dac-form-label dac-form-aside"><span data-t="newsletter.confirmMailingList"></span><span class="dac-form-required">*</span></label> </div> </div> </div> <div class="dac-form-radio-group"> <div class="dac-media"> <div class="dac-media-figure"> <input type="checkbox" class="dac-form-checkbox" name="entry.2045036090" id="newsletter-terms" required value="I acknowledge that the information provided in this form will be subject to Google's privacy policy (https://www.google.com/policies/privacy/)."> <label for="newsletter-terms" class="dac-form-checkbox-button"></label> </div> <div class="dac-media-body"> <label for="newsletter-terms" class="dac-form-label dac-form-aside"><span data-t="newsletter.privacyPolicy" data-t-html></span><span class="dac-form-required">*</span></label> </div> </div> </div> </div> </div> </fieldset> </section> <footer class="dac-modal-footer"> <div class="cols"> <div class="col-2of5"> </div> </div> <button type="submit" value="Submit" class="dac-fab dac-primary dac-large dac-modal-action"><i class="dac-sprite dac-arrow-right"></i></button> </footer> </form> </section> <section class="dac-swap-section dac-right"> <div class="dac-modal-content"> <p class="newsletter-success-message" data-t="newsletter.successDetails"></p> </div> </section> </div> </div> </div> </div> <!-- end newsletter modal --> <!-- start reset language header modal --> <div data-modal="langform" class="dac-modal" id="langform"> <div class="dac-modal-container"> <div class="dac-modal-window"> <header class="dac-modal-header"> <div class="dac-modal-header-actions"> <button class="dac-modal-header-close" data-modal-toggle></button> </div> <section class="dac-swap-section dac-active dac-down"> <h2 class="norule dac-modal-header-title"></h2> </section> </header> <section class="dac-swap-section dac-active dac-left"> <section class="dac-modal-content"> <fieldset class="dac-form-fieldset"> <div class="cols"> <div class="col-2of2 langform-leftCol"> <p id="resetLangText"></p> <p id="resetLangCta"></p> </div> </div> </fieldset> </section> <footer class="dac-modal-footer" id="langfooter"> <div class="cols"> <div class="col-2of5"> </div> </div> <button class="button dac-primary dac-modal-action lang yes" data-t="newsletter.resetLangButtonYes" data-modal-toggle></button> <button class="button dac-primary dac-modal-action lang no" data-t="newsletter.resetLangButtonNo" data-modal-toggle></button> </a> </footer> </form> </section> </div> </div> </div> <!-- end langreset modal --> </div> <!-- end body-content --> <script src="https://developer.android.com/ytblogger_lists_unified.js" defer></script> <script src="/jd_lists_unified_en.js?v=17" defer></script> <script src="/reference/lists.js?v=17" defer></script> <script src="/reference/gcm_lists.js?v=17" defer></script> <script src="/reference/gms_lists.js?v=17" defer></script> <script> // Load localized metadata. (function(lang) { if (lang === 'en') { return; } // Write it to the document so it gets evaluated before DOMContentReady. document.write('<script src="/jd_lists_unified_' + lang + '.js?v=14" defer></' + 'script>'); })(getLangPref()) </script> </body> </html>