-->

  1. Download Device Drivers
  2. External Download Device For Android Pc
  3. Android Device Manager App Download
  4. External Download Device For Android Iphone

External storage refers to file storage that is not on internal storage and not exclusively accessible to the app that is responsible for the file. The primary purpose of external storage is to provide a place to put files that are meant to be shared between apps or that are too large to fit on the internal storage.

Historically speaking, external storage referred to a disk partition on removable media such as an SD card (was also known as portable storage). This distinction is no longer as relevant as Android devices have evolved and many Android devices no longer support removable storage. Instead some devices will allocate some of their internal non-volatile memory which Android to perform the same function removable media. This is known as emulated storage and is still considered to be external storage. Alternately, some Android devices may have multiple external storage partitions. For example, an Android tablet (in addition to its internal storage) might have emulated storage and one or more slots for an SD card. All of these partitions are treated by Android as external storage.

On devices that have multiple users, each user will have a dedicated directory on the primary external storage partition for their external storage. Apps running as one user will not have access to files from another user on the device. The files for all users are still world-readable and world-writeable; however, Android will sandbox each user profile fromthe others.

Download Device Drivers

Reading and writing to files is almost identical in Xamarin.Android as it is to any other .NET application. The Xamarin.Android app determines the path to the file that will be manipulated, then uses standard .NET idioms for file access. Because the actual paths to internal and external storage may vary from device to device or from Android version to Android version, it is not recommended to hard code the path to the files. Instead, Xamarin.Android exposes the native Android APIs that will help with determining the path to files on internal and external storage.

Feb 24, 2017  Why to Export Android Files to External Hard Drive? With the development of technologies, more and more functions are now integrating in one Android device, which can satisfy the needs of Android users in all respects, such as connecting with friends and families via phone calls and messages, memorizing the special moments via photo taking and video shooting abilities within the device. Connect External Hard Drive to Android Smartphone: Nowadays a lot of Smartphones with Android OS supports 'OTG ' and it is possible to connect a lot of different hardware, but not all as easy, as it looks at the first glance.Sometimes, even USB Thumb Drive won't work with smartphone, reasons for.

This guide will discuss the concepts and APIs in Android that are specific to external storage.

Public and private files on external storage

There are two different types of files that an app may keep on external storage:

  • Private files – Private files are files that are specific to your application (but are still world-readable and world-writable). Android expects that private files are stored in a specific directory on external storage. Even though the files are called 'private', they are still visible and accessible by other apps on the device, they are not afforded any special protection by Android.

  • Public files – These are files that are not considered to be specific to the application and are meant to be freely shared.

The differences between these files is primarily conceptual. Private files are private in the sense that they are considered to be a part of the application, while public files are any other files that exist on external storage. Android provides two different APIs for resolving the paths to private and public files, but otherwise the same .NET APIs are used to read and write to these files. These are the same APIs that are discussed in the section on reading and writing.

Private external files

Private external files are considered to be specific to an application (similar to internal files) but are being kept on external storage for any number of reasons (such as being too large for internal storage). Similar to internal files, these files will be deleted when the app is uninstalled by the user.

The primary location for private external files is found by calling the method Android.Content.Context.GetExternalFilesDir(string type). This method will return a Java.IO.File object that represents the private external storage directory for the app. Passing null to this method will return the path to the user's storage directory for the application. As an example, for an application with the package name com.companyname.app, the 'root' directory of the private external files would be:

This document will refer to the storage directory for private files on external storage as PRIVATE_EXTERNAL_STORAGE.

The parameter for GetExternalFilesDir() is a string that specifies an application directory. This is a directory intended to provide a standard location for a logical organization of files. The string values are available through constants on the Android.OS.Environment class:

Android.OS.EnvironmentDirectory
DirectoryAlarmsPRIVATE_EXTERNAL_STORAGE/Alarms
DirectoryDcimPRIVATE_EXTERNAL_STORAGE/DCIM
DirectoryDownloadsPRIVATE_EXTERNAL_STORAGE/Download
DirectoryDocumentsPRIVATE_EXTERNAL_STORAGE/Documents
DirectoryMoviesPRIVATE_EXTERNAL_STORAGE/Movies
DirectoryMusicPRIVATE_EXTERNAL_STORAGE/Music
DirectoryNotificationsPRIVATE_EXTERNAL_STORAGE/Notifications
DirectoryPodcastsPRIVATE_EXTERNAL_STORAGE/Podcasts
DirectoryRingtonesPRIVATE_EXTERNAL_STORAGE/Ringtones
DirectoryPicturesPRIVATE_EXTERNAL_STORAGE/Pictures

For devices that have multiple external storage partitions, each partition will have a directory that is intended for private files. The method Android.Content.Context.GetExternalFilesDirs(string type) will return an array of Java.IO.Files. Each object will represent a private application-specific directory on all shared/external storage devices where the application can place the files it owns.

Important

The exact path to the private external storage directory can vary from device to device and between versions of Android. Because of this, apps must not hard code the path to this directory, and instead use the Xamarin.Android APIs, such as Android.Content.Context.GetExternalFilesDir().

External Download Device For Android Pc

External download device for android pc

Public external files

Public files are files that exist on external storage that are not stored in the directory that Android allocates for private files. Public files will not be deleted when the app is uninstalled. Android apps must be granted permission before they can read or write any public files. It is possible for public files to exist anywhere on external storage, but by convention Android expects public files to exist in the directory identified by the property Android.OS.Environment.ExternalStorageDirectory. This property will return a Java.IO.File object that represents the primary external storage directory. As an example, Android.OS.Environment.ExternalStorageDirectory may refer to the following directory:

This document will refer to the storage directory for public files on external storage as PUBLIC_EXTERNAL_STORAGE.

Android also supports the concept of application directories on PUBLIC_EXTERNAL_STORAGE. These directories are exactly the same as the application directories for PRIVATE_EXTERNAL_STORAGE and are described in the table in the previous section. The method Android.OS.Environment.GetExternalStoragePublicDirectory(string directoryType) will return a Java.IO.File object that correspond to a public application directory. The directoryType parameter is a mandatory parameter and cannot be null.

For example, calling Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDocuments).AbsolutePath will return a string which will resemble:

Important

The exact path to the public external storage directory can vary from device to device and between versions of Android. Because of this, apps must not hard code the path to this directory, and instead use the Xamarin.Android APIs, such as Android.OS.Environment.ExternalStorageDirectory.

Working with external storage

Once a Xamarin.Android app has obtained the full path to a file, it should utilize any of the standard .NET APIs for creating, reading, writing, or deleting files. This maximizes the amount of cross platform compatible code for an app. However, before attempting to access a file a Xamarin.Android app must ensure that is it possible to access that file.

  1. Verify external storage – Depending on the nature of the external storage, it is possible that it might not be mounted and usable by the app. All apps should check the state of the external storage before attempting to use it.
  2. Perform a runtime permission check – An Android app must request permission from the user in order to access external storage. This means that a run time permission request should be performed prior to any file access. The guide Permissions In Xamarin.Android contains more details on Android permissions.

Each of these two tasks will be discussed below.

Verifying that external storage is available

The first step before writing to external storage is to check that it is readable or writeable. The Android.OS.Environment.ExternalStorageState property holds a string that identifies the state of the external storage. This property will return a string that represents the state. This table is a list of the ExternalStorageState values that might be returned by Environment.ExternalStorageState:

ExternalStorageStateDescription
MediaBadRemovalThe media was abruptly removed without being properly unmounted.
MediaCheckingThe media is present but undergoing a disk check.
MediaEjectingMedia is in the process of being unmounted and ejected.
MediaMountedMedia is mounted and can be read or written to.
MediaMountedReadOnlyMedia is mounted but can only be read from.
MediaNofsMedia is present but does not contain a filesystem suitable for Android.
MediaRemovedThere is no media present.
MediaSharedMedia is present, but is not mounted. It is being shared via USB with another device.
MediaUnknownThe state of the media is unrecognized by Android.
MediaUnmountableThe media is present but cannot be mounted by Android.
MediaUnmountedThe media is present but is not mounted.

Most Android apps will only need to check if external storage is mounted. The following code snippet shows how to verify that external storage is mounted for read-only access or read-write access:

External storage permissions

Android considers accessing external storage to be a dangerous permission, which typically requires the user to grant their permission to access the resource. The user may revoke this permission at any time. This means that a run time permission request should be performed prior to any file access. Apps are automatically granted permissions to read and write their own private files. It is possible for apps to read and write the private files that belong to other apps after being granted permission by the user.

Download

All Android apps must declare one of the two permissions for external storage in the AndroidManifest.xml . To identify the permissions, one of the following two uses-permission elements must be add to AndroidManifest.xml:

Note

If the user grants WRITE_EXTERNAL_STORAGE, then READ_EXTERNAL_STORAGE is also implicitly granted. It is not necessary to request both permissions in AndroidManifest.xml.

The permissions may also be added using the Android Manifest tab of the solution properties:

The permissions may also be added using the Android Manifest tab of the solution properties pad:

Generally speaking, all dangerous permissions must be approved by the user. The permissions for external storage are an anomaly in that there are exceptions to this rule, depending on the version of Android that the app is running:

For more information on performing runtime permission requests, please consult the guide Permissions In Xamarin.Android. The monodroid-sampleLocalFiles also demonstrates one way of performing runtime permission checks.

Android Device Manager App Download

Granting and revoking permissions with ADB

In the course of developing an Android app, it may be necessary to grant and revoke permissions to test the various work flows involved with runtime permission checks. It is possible to do this at the command prompt using ADB. The following command line snippets demonstrate how to grant or revoke permissions using ADB for an Android app whose package name is com.companyname.app:

Deleting files

Any of the standard C# APIs can be used to delete a file from external storage, such as System.IO.File.Delete. It is also possible to use the Java APIs at the expense of code portability. For example:

Related Links

-->

A common requirement for Android apps is to manipulate files – saving pictures, downloading documents, or exporting data to share with other programs. Android (which is based on Linux) supports this by providing space for file storage. Android groups the filesystem into two different types of storage:

  • Internal Storage – this is a portion of the file system that can be accessed only by the application or the operating system.
  • External Storage – this is a partition for the storage of files that is accessible by all apps, the user, and possibly other devices. On some devices, external storage may be removable (such as an SD card).

These groupings are conceptual only, and don't necessarily refer to a single partition or directory on the device. An Android device will always provide partition for internal storage and external storage. It is possible that certain devices may have multiple partitions that are considered to be external storage. Regardless of the partition the APIs for reading, writing, or creating files is the same. There are two sets of APIs that a Xamarin.Android application may use for file access:

  1. The .NET APIs (provided by Mono and wrapped by Xamarin.Android) – These includes the file system helpers provided by Xamarin.Essentials. The .NET APIs provide the best cross-platform compatibility and as such the focus of this guide will be on these APIs.
  2. The native Java file access APIs (provided by Java and wrapped by Xamarin.Android) – Java provides its own APIs for reading and writing files. These are a completely acceptable alternative to the .NET APIs, but are specific to Android and are not suitable for apps that are intended to be cross-platform.

Reading and writing to files is almost identical in Xamarin.Android as it is to any other .NET application. The Xamarin.Android app determines the path to the file that will be manipulated, then uses standard .NET idioms for file access. Because the actual paths to internal and external storage may vary from device to device or from Android version to Android version, it is not recommended to hard code the path to the files. Instead, use the Xamarin.Android APIs to determine the path to files. That way, the .NET APIs for reading and writing files exposes the native Android APIs that will help with determining the path to files on internal and external storage.

Before discussing the APIs involved with file access, it is important to understand some of the details surrounding internal and external storage. This will be discussed in the next section.

Internal vs external storage

Conceptually, internal storage and external storage are very similar – they are both places at which a Xamarin.Android app may save files. This similarity may be confusing for developers who are not familiar with Android as it is not clear when an app should use internal storage vs external storage.

Internal storage refers to the non-volatile memory that Android allocates to the operating system, APKs, and for individual apps. This space is not accessible except by the operating system or apps. Android will allocate a directory in the internal storage partition for each app. When the app is uninstalled, all the files that are kept on internal storage in that directory will also be deleted. Internal storage is best suited for files that are only accessible to the app and that will not be shared with other apps or will have very little value once the app is uninstalled. On Android 6.0 or higher, files on internal storage may be automatically backed up by Google using the Auto Backup feature in Android 6.0. Internal storage has the following disadvantages:

  • Files cannot be shared.
  • Files will be deleted when the app is uninstalled.
  • The space available on internal storage maybe limited.

External storage refers to file storage that is not internal storage and not exclusively accessible to an app. The primary purpose of external storage is to provide a place to put files that are meant to be shared between apps or that are too large to fit on the internal storage. The advantage of external storage is that it typically has much more space for files than internal storage. However, external storage is not always guaranteed to be present on a device and may require special permission from the user to access it.

Note

For devices that support multiple users, Android will provide each user their own directory on both internal and external storage. This directory is inaccessible to other users on the device. This separation is invisible to apps as long as they do not hardcode paths to files on internal or external storage.

As a rule of thumb, Xamarin.Android apps should prefer saving their files on internal storage when it is reasonable, and rely on external storage when files need to be shared with other apps, are very large, or should be retained even if the app is uninstalled. For example, a configuration file is best suited for a internal storage as it has no importance except to the app that creates it. In contrast, photos are a good candidate for external storage. They can be very large and in many cases the user may want to share them or access them even if the app is uninstalled.

This guide will focus on internal storage. Please see the guide External storage for details on using external storage in a Xamarin.Android application.

Working with internal storage

External Download Device For Android Iphone

The internal storage directory for an application is determined by the operating system, and is exposed to Android apps by the Android.Content.Context.FilesDir property. This will return a Java.IO.File object representing the directory that Android has dedicated exclusively for the app. For example, an app with the package name com.companyname the internal storage directory might be:

This document will refer to the internal storage directory as INTERNAL_STORAGE.

Important

The exact path to the internal storage directory can vary from device to device and between versions of Android. Because of this, apps must not hard code the path to the internal files storage directory, and instead use the Xamarin.Android APIs, such as System.Environment.GetFolderPath().

To maximize code sharing, Xamarin.Android apps (or Xamarin.Forms apps targeting Xamarin.Android) should use the System.Environment.GetFolderPath() method. In Xamarin.Android, this method will return a string for a directory that is the same location as Android.Content.Context.FilesDir. This method takes an enum, System.Environment.SpecialFolder, which is used to identify a set of enumerated constants that represent the paths of special folders used by the operating system. Not all of the System.Environment.SpecialFolder values will map to a valid directory on Xamarin.Android. The following table describes what path can be expected for a given value of System.Environment.SpecialFolder:

System.Environment.SpecialFolderPath
ApplicationDataINTERNAL_STORAGE/.config
DesktopINTERNAL_STORAGE/Desktop
LocalApplicationDataINTERNAL_STORAGE/.local/share
MyDocumentsINTERNAL_STORAGE
MyMusicINTERNAL_STORAGE/Music
MyPicturesINTERNAL_STORAGE/Pictures
MyVideosINTERNAL_STORAGE/Videos
PersonalINTERNAL_STORAGE

Reading or Writing to files on internal storage

Any of the C# APIs for writing to a file are sufficient; all that is necessary is to get the path to the file that is in the directory allocated to the application. It is strongly recommended that the async versions of the .NET APIs are used to minimize any issues that may be associate with file access blocking the main thread.

This code snippet is one example of writing an integer to a UTF-8 text file to the internal storage directory of an application:

The next code snippet provides one way to read an integer value that was stored in a text file:

Using Xamarin.Essentials – File System Helpers

Xamarin.Essentials is a set of APIs for writing cross-platform compatible code. The File System Helpers is a class that contains a series of helpers to simplify locating the application's cache and data directories. This code snippet provides an example of how to find the internal storage directory and the cache directory for an app:

Hiding files from the MediaStore

The MediaStore is an Android component that collects meta data about media files (videos, music, images) on an Android device. Its purpose is simplify the sharing of these files across all Android apps on the device.

Private files will not show up as shareable media. For example, if an app saves a picture to its private external storage, then that file will not be picked up by the media scanner (MediaStore).

Public files will be picked up by MediaStore. Directories that have a zero byte file name .NOMEDIA will not be scanned by MediaStore.

Related Links