Android - How can i install my app to sd card - android

I created my android app. I installed my telephone. But it was saved my telephone. I want to save APP and DATABASE to my sd card. Because when people formatted telephone, app and db datas will not delete

In your manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="YOUR_PACKAGE"
android:installLocation="internalOnly"
android:installLocation can be changed to preferExternal for preference to external storage. But this doesn't gurantee the application will be install on external storage, as from the Android references
The application prefers to be installed on the external storage (SD
card). There is no guarantee that the system will honor this request.
The application might be installed on internal storage if the external
media is unavailable or full. Once installed, the user can move the
application to either internal or external storage through the system
settings.
Read here for more information about manifest elements(as refered by a respected user below)
If the app data is stored as SharedPreference it will be automatically cleared on device format, so you may opt to save your preferences to External Storage from the application using custom preference files.
Read here for ways to store data on android.

Related

How to force android to install app on internal memory

I've an app that i download from private server, it installs ok on most phones but i'm having problems installing it on a HTC Desire C. The phone has no sdcard present. I've searched around and found a manifest setting that should hint at internal storage or say that there is at least no preference to where the app is installed.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.carefreegroup"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto" >
This does not work however.
How can i tell android that the app MUST be installed on the internal memory
Thanks Matt
set in Manifest
android:installLocation="internalOnly"
this will install app in internal storage and will not install it at all if there is no space in internal memory
http://developer.android.com/guide/topics/manifest/manifest-element.html
The attribute android:installLocation can have following possible values.
internalOnly: The application must be installed on the internal device storage only. If this is set, the application will never be installed on the external storage. If the internal storage is full, then the system will not install the application. This is also the default behavior if you do not define android:installLocation.
auto: The application may be installed on the external storage, but the system will install the application on the internal storage by default. If the internal storage is full, then the system will install it on the external storage. Once installed, the user can move the application to either internal or external storage through the system settings.
preferExternal: The application prefers to be installed on the external storage (SD card). There is no guarantee that the system will honor this request. The application might be installed on internal storage if the external media is unavailable or full, or if the application uses the forward-locking mechanism (not supported on external storage). Once installed, the user can move the application to either internal or external storage through the system settings.
According to the docs if you do not set that preference, the app will be installed on internal storage and it won't be movable.

How to prevent Android app installation if SDCard absent?

My code logic needs an SD card installed in the device. I have added a check for this case in the application's splash screen, but would like to inform users before they download/install this app. Is there a way to achieve this ?
Thanks !
There is no way to do this before the app installs, as the only way to limit such things is by using the <uses-feature> tag. However, that tag has no options for storage requirements. The best warning you can give is to prominently include it in your app description.
On the other hand, every device I've ever heard of an encountered has some form of external storage, be it a SD Card or inbuilt memory mounted as external storage. What you're doing by using the Splash Screen to check for the external storage is the best way to do this, as there is no other option.
There's no way to do that. Your app have to be installed to be able to check user's environment. You could try to to enforce SD card installation of your app, so if there's none Google Play might (not tested) simply not allow app installation at all, but it will not solve your problem as user will still do not know why. Solution is to clearly state in product description that SD card is mandatory. But note, that requiring SD card is risky as many devices does not have any while still offer external storage. My suggestion - just add note about storage requirements and let system deal with it.
I think it is NOT POSSIBLE . You are checking the sdcard on splash screen and prevent user for next process is the right solution or Use android:installLocation for install android application on sdcard.
Beginning with API Level 8, you can allow your application to be
installed on the external storage (for example, the device's SD card).
This is an optional feature you can declare for your application with
the android:installLocation manifest attribute.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="preferExternal"
... >
If you declare "preferExternal", you request that your application be
installed on the external storage, but the system does not guarantee
that your application will be installed on the external storage. If
the external storage is full, the system will install it on the
internal storage. The user can also move your application between the
two locations.
When your application is installed on the external storage:
There is no effect on the application performance so long as the
external storage is mounted on the device.
The .apk file is saved on the external storage, but all private user
data, databases, optimized .dex files, and extracted native code are
saved on the internal device memory.
The unique container in which your application is stored is encrypted
with a randomly generated key that can be decrypted only by the
device that originally installed it. Thus, an application installed
on an SD card works for only one device.
The user can move your application to the internal storage through
the system settings.
Look Here for more details .

Is there a way to see what data stores each app in phone memory/on sd card?

I want to track everything that apps store in phone memory/on sd card, so I can delete it if the app is uninstalled. Is this possible? If not, how can I get all the files from phone memory/sd card?
there is no way to "track" what your application creates, i think..
generally, the app stores data in the Cache directory, which is :
"<storage directory>/data/<your package name>/"
on a device which supports external storage, the "storage directory" is generally "/mnt/sdcard"
you can read the documentation to learn how to use the External storage to save files you create through your application.
I'd also like to point out that there is no way for you to know when your app is being uninstalled, so you can't delete the files before uninstall manually anyway,if that's what you intend to do. The android system itself removes the files stored in your cache directory, though.

How To Access External and internal storage?

I actually want to access the files on android system. I manage to read the files and directories in the external storage of android.
My questions are :
How can I access the directories and files of the internal storage(Specially videos, pics all of the applications which runs in android).
Where are stored the data of each application which installed in internal storage?
Is it possible to transfer data which exists in the internal storage (from internal memory to external storage?
I read that external storage is world-readable? what does that mean?(if a create an application then this application can access all the files that installed in external storage?)
By default, an app cannot access data stored by another app. Permissions are applied to internal storage that make data written by an application not accessible outside of that application (your app cannot read anything written by another app). This can be changed, where an application can specify different permissions for ITS OWN data; basically, an app can allow others to read its data. However, if an app does not specifically set its permissions to allow this, other apps cannot access its data. This is a fundamental principle of the Android security/isolation model and is done at the Linux/kernel level, as each app runs under its own Linux UID and permissions are set within the filesystem only allowing that UID access to the app's directory structure (group and world permissions are set to 0 by default).
This all goes out the window if you have access to root on the device (rooted phone and your app runs with root permissions), but we should consider that out-of-scope for your question.
External (SD card) storage is different in that it is considered free-for-all and permissions are not applied there (this is originally due to the filesystem typically used in SD not supporting permissions). Any app can usually read anything written to the SD card by any other app, unless the original app does something to protect it (encrypt, etc).
This is all explained in great detail in Application Security for the Android Platform, just published by O'Reilly.
You have to write FileProvider to access the app specific files with another app.

Android – Where to store downloaded content, internal versus external storage?

A number of separate, but related, questions concerning where to store downloaded content within my application.
I have an application that downloads content from a central server. This content is sometimes premium content, or at least content where the publisher does not want it freely distributed. I understand that the “external” storage is readily accessible whereas the “internal” storage is protected, unless the phone is rooted.
If the application is installed on the SDCARD (as mine is configured to be) then is the “internal” storage also physically on the SDCARD? Thus if my SDCARD installed application downloads, say, 100MB of content to internal storage then is it actually ending up on the SDCARD, or is it ending up in the device’s physical on-board storage?
If the application is installed on the SDCARD, and the “internal” storage with the downloaded content is on the SDCARD then is it physically stored in an open format or is it encrypted? I seem to remember reading that an application stored on an SDCARD is encrypted. Does this also apply to the “internal” storage?
(Deleted question about storing files in a single directory as Context.getDir() implies that a directory system can be created and maintained in the internal storage)
Is there a better approach?
Did a bunch of experimentation and came to the following conclusions with Android 2.2 on a Motorola Droid 2:
When an application is installed/moved to the SDCARD then it is stored as an .asec file in the hidden /.android_secure directory on the SDCARD. This is an encrypted and compressed file.
When the application creates data files in the "internal storage" they are stored within the internal memory of the device, not on the SDCARD.
The Settings / Manage Applications details dialog for the application has a value for "Data" - this is the amount of data the application is using within its internal storage, that is in the internal memory not on the SDCARD
The external storage does end up on the SDACRD under the /Android/data directory
Clearing the data from the Settings / Manage Applications details dialog does indeed wipe everything, which means that the installed application needs to have enough knowledge/logic to handle the "no data" situation.
My app is a download content app. What this all means to me is that:
There is little real value in storing my small app on the SDCARD given that the bulk of the storage it will consume on the phone will be in the device's internal memory. Except of course that its always good to allow the application to install on the SDCARD.
The installation package needs to be able to recover the user's downloaded content if it is wiped by the user.
The concept of storing a unique installation id in the internal memory works well until a user deletes the application's data and hence causes a new installation id to be computed. Thus to be able to remember what content has been downloaded to a device requires a user account on a central server that the user creates/logs into whenever the application starts from scratch.

Categories

Resources