Hi Milan,

Have you experimented with this[1] SDK method? It might solve the issue you
are having. Ideally the usage of memory info retrieval would be, we can
know if the devise has enough memory to install an application, prior to
issuing an operation.

[1].
http://developer.android.com/reference/android/os/Environment.html#isExternalStorageRemovable()

Regards,
Inosh

On Thu, Jun 4, 2015 at 11:20 AM, Milan Perera <[email protected]> wrote:

> Hi Inosh,
>
> The Android's API suggested way of getting external storage details as
> follows.
>
> String storagePath = 
> android.os.Environment.getExternalStorageDirectory().getPath(); // This gives 
> the '/storage/emulated/0'
> StatFs directoryStatus = new StatFs(storagePath);
>
> So this is what we have used in our android agent as well. Even though the
> word 'external' is used here, it does not mean the external storage that we
> expect.
> Usually what we think as the external storage is the external SD/microSD
> card. However, as it mentioned in the API [1], 'external' is considered as
> media/shared storage. It is a filesystem that can hold a relatively large
> amount of data and that is shared across all applications (does not enforce
> permissions). Traditionally this is a SD card, but it may also be
> implemented as built-in storage in a device that is distinct from the
> protected internal storage and can be mounted as a filesystem on a device.
>
> Therefor even if we do the check "
> *android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)*",
> it always returns true since nowadays almost all the android devices are
> shipped with built-in external storage.
>
> So my suggestion is to calculate internal and external memories as follows.
>
> String externalStorage = System.getenv("EXTERNAL_STORAGE"); // returns 
> '/storage/emulated/0'
> String secondaryStorage = System.getenv("SECONDARY_STORAGE"); // returns 
> 'null' if device does not support external-sd-card or returns 
> '/storage/extSdCard'
>
> Then we will be able get the accurate mount point details for both in
> internal (externalStorage) and external (secondaryStorage) storage.
>
> [1]
> http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory%28%29
>
> Regards,
>
> On Wed, Jun 3, 2015 at 3:10 PM, Inosh Perera <[email protected]> wrote:
>
>> Hi Dilan/Milan,
>>
>> In Android, as "EXTERNAL_MEMORY" implies both "INTERNAL+EXTERNAL"
>> Could you explain this statement bit more? Isn't external memory normally
>> the externally mounted SD card.
>>
>> Regards,
>> Inosh
>>
>>
>> On Wed, Jun 3, 2015 at 2:50 PM, Dilan Udara Ariyaratne <[email protected]>
>> wrote:
>>
>>> Hi All,
>>>
>>> In Android, as "EXTERNAL_MEMORY" implies both "INTERNAL+EXTERNAL", to
>>> accurately obtain information
>>> from the agent, let's do a small calculation at the agent side to
>>> retrieve correct values as follows.
>>>
>>> Current payload retrieved :
>>>
>>> {
>>>     "EXTERNAL_TOTAL_MEMORY": "4.92",
>>>     "INTERNAL_AVAILABLE_MEMORY": "4.78",
>>>     "EXTERNAL_AVAILABLE_MEMORY": "4.78",
>>>     "OPERATOR": "Android",
>>>     "BATTERY_LEVEL": "51",
>>>     "INTERNAL_TOTAL_MEMORY": "4.92"
>>> }
>>>
>>> Here we can obtain the correct value for "EXTERNAL_TOTAL_MEMORY" as
>>> EXTERNAL_TOTAL_MEMORY = EXTERNAL_TOTAL_MEMORY - INTERNAL_TOTAL_MEMORY
>>> Similarly, the correct value for "EXTERNAL_AVAILABLE_MEMORY" as
>>> EXTERNAL_AVAILABLE_MEMORY = "EXTERNAL_AVAILABLE_MEMORY" -
>>> INTERNAL_AVAILABLE_MEMORY
>>>
>>> So the final outcome would look something similar to the following.
>>>
>>> {
>>>     "OPERATOR": "Android",
>>>     "BATTERY_LEVEL": "51",
>>>     "INTERNAL_TOTAL_MEMORY": "4.92",
>>>     "INTERNAL_AVAILABLE_MEMORY": "4.78",
>>>     "EXTERNAL_TOTAL_MEMORY": "0.00",
>>>     "EXTERNAL_AVAILABLE_MEMORY": "0.00"
>>> }
>>>
>>> - - - - - - - - - - - - - - - - - - - - - - - - - -
>>>
>>> Cheers.
>>>
>>> *Dilan U. Ariyaratne*
>>> Software Engineer
>>> WSO2 Inc. <http://wso2.com/>
>>> Mobile: +94775149066
>>> lean . enterprise . middleware
>>>
>>
>>
>>
>> --
>> Inosh Perera
>> Software Engineer, WSO2 Inc.
>> Tel: 0785293686
>>
>
>
>
> --
> Milan Harindu Perera
> Software Engineer
> *WSO2, Inc*
> (+94) 77 309 7088
> lean . enterprise . middleware
> <http://lk.linkedin.com/in/milanharinduperera>
>



-- 
Inosh Perera
Software Engineer, WSO2 Inc.
Tel: 0785293686
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to