Android program files path

lopspower / README.md

All Android Directory Path

1) System directories

⚠️ We can’t write to these folers

Method Result
Environment.getDataDirectory() /data
Environment.getDownloadCacheDirectory() /cache
Environment.getRootDirectory() /system

2) External storage directories

⚠️ Need WRITE_EXTERNAL_STORAGE Permission

Method Result
Environment.getExternalStorageDirectory() /storage/sdcard0
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_ALARMS) /storage/sdcard0/Alarms
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) /storage/sdcard0/DCIM
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) /storage/sdcard0/Download
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) /storage/sdcard0/Movies
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) /storage/sdcard0/Music
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS) /storage/sdcard0/Notifications
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) /storage/sdcard0/Pictures
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS) /storage/sdcard0/Podcasts
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES) /storage/sdcard0/Ringtones

3) Application directories

Method Result
getCacheDir() /data/data/package/cache
getFilesDir() /data/data/package/files
getFilesDir().getParent() /data/data/package

4) Application External storage directories

Источник

Learn how to use fileprovider in Android with example

Today we will be looking at the one of the confusing topic in android i.e. FileProvider. It is confusing for beginners as they do not understand, how to use it and why to use it. So let us learn how to use FileProvider in Android with an example project.

If you just want to get file path from internal document picker check out this article: here.

What is a FileProvider in Android ?

How long have you been exploring this concept of file provider in android ? I think it’s been quite a while but you have not found a easier explanation about it. Here I will simply explain what a fileprovider is and why even bother with it in the first place ?

FileProvider is simply a special subclass of ContentProvider which allows manipulating user data on storage more secure and easy ( not really at first ). It simply creates a content:/// URI instead of file:/// which makes secure.

How does it make the files accessing more secure ? To answer that question we must understand that using the FileProvider only a content:/// is exposed meaning the actual file location is hidden, and adds security.

But adding security means some headaches for developers especially for someone who is just starting with the Android Development. I will break down BITS of FileProvider below so let us continue.

Using FileProvider in Android application

Let us see how we can use the FileProvider in our application step by step.

Setting up FileProvider in manifest

Let us see how we can add the FileProvider definition in out manifest file. Add the code below in your AndroidManifest.xml file.

Creating file_paths.xml file to add our file paths

Now that we have added the FileProvider definition in our AndroidManifest.xml let us look at the code.

You will receive an error at the code above because we have to mention the path for the FileProvider to access. Which we will do below but first lets create an Android resource directory.

Go to projects side bar and navigate to app > res . Right click there and click Android Resource Directory . name the directory xml and select xml from drop down.

After that create the file_paths.xml in the xml directory and add the contents below.

Confused about what the code above means ? Don’t be because I will break everything down.

Understanding what each file path actually mean

Now we have to understand something before proceeding. Everything is scoped with file paths. Meaning accessing anything outside defined file paths will cause a runtime exception.

Each type of paths you see between

serve a purpose. And we are going to learn what that is with this fileprovider Android example.

Note: name and path is same for each. where name is the pointer and path is the actual location.

This is the path will will be accessible by invoking this method Context.getFilesDir() . We will get a file instance pointing to the files dir. This directory is located in the internal storage area on your device.

Same as above the only difference is it resides in the external removable storage area of the device. The root path is returned by Context.getExternalFilesDir(null) .

/>

This is same as files-path but it provides the root directory for internal area cache. Which is what you get when you invoke Context.getCacheDir() .

Same as the the local cache but the difference is the cache directory is located in external storage area. Which you will get once you use Context.getExternalCacheDir().

This path also defines the media directory located on the external storage area of your device. Which returns the path provided by Context.getExternalMediaDirs() . But this method is deprecated and MediaStore must be used.

This path is relative to the external root of your device. And you can get this file by Environment.getExternalStorageDirectory() . As you normally would, this method is marked deprecated and must not be used normally. Always use file providers for any file reading.

Getting the content URI

Now that we have understood what each means. Let us move forward and retrieve out URI, as it was our main goal.

We have set everything up let us create a temporary file in our cache directory. Let us write the code in out MainActivity as

Now that will create a file named test_file.txt in our cache directory, remember ?

Next we will update the URI into our TextView just to make sure it worked.

Look at the FILE_AUTHORITY which we have declared in the companion object block. The full code for MainActivity is provided below:

Sharing the URI using ShareCompat.IntentBuilder

Let us explore how we can share the URI using the ShareCompat.IntentBuilder here.

This will open up the possible applications for image/jpg , you can change that as per your need.

Now we are done. What you do with the URI is up to you. Next time we will learn how to get the actual file from URI. Till then, keep learning.

For reference you can checkout official documentation, here.

Источник

Где можно задать свои расположения пакета SDK для Android?

в Visual Studio перейдите в меню сервис параметры > Xamarin > Android Параметры , чтобы просмотреть и задать расположение пакет SDK для Android:

Расположение по умолчанию для каждого пути выглядит следующим образом:

Расположение пакета средств разработки Java:

C:\Program Филес\жава\ jdk1.8.0_131

Расположение пакета SDK для Android

C:\Program Files (x86) \Андроид\андроид-СДК

Расположение пакета Android NDK:

C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r13b

Обратите внимание, что номер версии NDK может отличаться. Например, вместо android-ndk-r13b может быть более ранняя версия, например android-ndk-r10e.

Чтобы задать расположение пакета SDK для Android, введите полный путь к каталогу пакета SDK для Android в поле Расположение пакета SDK для Android. Вы можете перейти к расположению пакета SDK для Android в проводнике, скопировать путь из адресной строки и вставить этот путь в поле Расположение пакета SDK для Android. Например, если расположение пакет SDK для Android находится на к:\усерс\усернаме\аппдата\локал\андроид\сдк, очистите старый путь в поле Расположение пакет SDK для Android , вставьте этот путь и нажмите кнопку ОК.

в Visual Studio для Mac перейдите к параметрам проекты > расположение пакета SDK для > Android. На странице Android перейдите на вкладку Расположения, чтобы просмотреть и задать расположение пакета SDK:

Расположение по умолчанию для каждого пути выглядит следующим образом:

Расположение пакета SDK для Android

Расположение пакета Android NDK:

Расположение пакета SDK для Java (JDK):

/usr

Обратите внимание, что номер версии NDK может отличаться. Например, вместо android-ndk-r14b может быть более ранняя версия, например android-ndk-r10e.

Чтобы задать расположение пакета SDK для Android, введите полный путь к каталогу пакета SDK для Android в поле Расположение пакета SDK для Android. Можно выбрать папку пакет SDK для Android в Finder, нажать клавиши CTRL + ⌘ + I , чтобы просмотреть сведения о папке, щелкнуть и перетащить путь справа от раздела :, скопировать, а затем вставить его в поле Расположение пакет SDK для Android на вкладке расположения . Например, если расположение пакет SDK для Android находится в папке

/либрари/девелопер/андроид/СДК, очистите старый путь в поле Расположение пакет SDK для Android , вставьте этот путь и нажмите кнопку ОК.

Источник

Data and file storage overview

Android uses a file system that’s similar to disk-based file systems on other platforms. The system provides several options for you to save your app data:

  • App-specific storage: Store files that are meant for your app’s use only, either in dedicated directories within an internal storage volume or different dedicated directories within external storage. Use the directories within internal storage to save sensitive information that other apps shouldn’t access.
  • Shared storage: Store files that your app intends to share with other apps, including media, documents, and other files.
  • Preferences: Store private, primitive data in key-value pairs.
  • Databases: Store structured data in a private database using the Room persistence library.

The characteristics of these options are summarized in the following table:

Type of content Access method Permissions needed Can other apps access? Files removed on app uninstall?
App-specific files Files meant for your app’s use only From internal storage, getFilesDir() or getCacheDir()

From external storage, getExternalFilesDir() or getExternalCacheDir()

Never needed for internal storage

Not needed for external storage when your app is used on devices that run Android 4.4 (API level 19) or higher

No Yes
Media Shareable media files (images, audio files, videos) MediaStore API READ_EXTERNAL_STORAGE when accessing other apps’ files on Android 11 (API level 30) or higher

READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE when accessing other apps’ files on Android 10 (API level 29)

Permissions are required for all files on Android 9 (API level 28) or lower

Yes, though the other app needs the READ_EXTERNAL_STORAGE permission No
Documents and other files Other types of shareable content, including downloaded files Storage Access Framework None Yes, through the system file picker No
App preferences Key-value pairs Jetpack Preferences library None No Yes
Database Structured data Room persistence library None No Yes

The solution you choose depends on your specific needs:

How much space does your data require? Internal storage has limited space for app-specific data. Use other types of storage if you need to save a substantial amount of data. How reliable does data access need to be? If your app’s basic functionality requires certain data, such as when your app is starting up, place the data within internal storage directory or a database. App-specific files that are stored in external storage aren’t always accessible because some devices allow users to remove a physical device that corresponds to external storage. What kind of data do you need to store? If you have data that’s only meaningful for your app, use app-specific storage. For shareable media content, use shared storage so that other apps can access the content. For structured data, use either preferences (for key-value data) or a database (for data that contains more than 2 columns). Should the data be private to your app? When storing sensitive data—data that shouldn’t be accessible from any other app—use internal storage, preferences, or a database. Internal storage has the added benefit of the data being hidden from users.

Categories of storage locations

Android provides two types of physical storage locations: internal storage and external storage. On most devices, internal storage is smaller than external storage. However, internal storage is always available on all devices, making it a more reliable place to put data on which your app depends.

Removable volumes, such as an SD card, appear in the file system as part of external storage. Android represents these devices using a path, such as /sdcard .

Apps themselves are stored within internal storage by default. If your APK size is very large, however, you can indicate a preference within your app’s manifest file to install your app on external storage instead:

Permissions and access to external storage

On earlier versions of Android, apps needed to declare the READ_EXTERNAL_STORAGE permission to access any file outside the app-specific directories on external storage. Also, apps needed to declare the WRITE_EXTERNAL_STORAGE permission to write to any file outside the app-specific directory.

More recent versions of Android rely more on a file’s purpose than its location for determining an app’s ability to access, and write to, a given file. In particular, if your app targets Android 11 (API level 30) or higher, the WRITE_EXTERNAL_STORAGE permission doesn’t have any effect on your app’s access to storage. This purpose-based storage model improves user privacy because apps are given access only to the areas of the device’s file system that they actually use.

Android 11 introduces the MANAGE_EXTERNAL_STORAGE permission, which provides write access to files outside the app-specific directory and MediaStore . To learn more about this permission, and why most apps don’t need to declare it to fulfill their use cases, see the guide on how to manage all files on a storage device.

Scoped storage

To give users more control over their files and to limit file clutter, apps that target Android 10 (API level 29) and higher are given scoped access into external storage, or scoped storage, by default. Such apps have access only to the app-specific directory on external storage, as well as specific types of media that the app has created.

Use scoped storage unless your app needs access to a file that’s stored outside of an app-specific directory and outside of a directory that the MediaStore APIs can access. If you store app-specific files on external storage, you can make it easier to adopt scoped storage by placing these files in an app-specific directory on external storage. That way, your app maintains access to these files when scoped storage is enabled.

To prepare your app for scoped storage, view the storage use cases and best practices guide. If your app has another use case that isn’t covered by scoped storage, file a feature request. You can temporarily opt-out of using scoped storage.

View files on a device

To view the files stored on a device, use Android Studio’s Device File Explorer.

Additional resources

For more information about data storage, consult the following resources.

Videos

Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.

Источник

Читайте также:  Просмотр паролей wifi для андроид
Оцените статью