Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
react-native-device-info
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
放牛的园子
react-native-device-info
Commits
cbbbb159
Commit
cbbbb159
authored
Feb 05, 2018
by
Lana Petković
Committed by
Mehdi Achour
Feb 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add getFreeDiskStorage() and getTotalDiskCapacity() (#302)
parent
6e529cca
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
93 additions
and
2 deletions
+93
-2
CHANGELOG.md
CHANGELOG.md
+4
-0
README.md
README.md
+32
-0
RNDeviceInfo.m
RNDeviceInfo/RNDeviceInfo.m
+30
-2
RNDeviceModule.java
...c/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
+16
-0
deviceinfo.d.ts
deviceinfo.d.ts
+3
-0
deviceinfo.js
deviceinfo.js
+6
-0
deviceinfo.js.flow
deviceinfo.js.flow
+2
-0
No files found.
CHANGELOG.md
View file @
cbbbb159
## Release Notes
### Next
*
Add
`getFreeDiskStorage`
and
`getTotalDiskCapacity`
(https://github.com/rebeccahughes/react-native-device-info/pull/302)
### 0.14.0
*
Fix tvOS support (https://github.com/rebeccahughes/react-native-device-info/pull/283)
...
...
README.md
View file @
cbbbb159
...
...
@@ -195,6 +195,7 @@ var DeviceInfo = require("react-native-device-info");
|
[
getDeviceLocale()
](
#getdevicelocale
)
|
`string`
| ✅ | ✅ | ✅ | 0.7.0 |
|
[
getDeviceName()
](
#getdevicename
)
|
`string`
| ✅ | ✅ | ✅ | ? |
|
[
getFirstInstallTime()
](
#getfirstinstalltime
)
|
`number`
| ❌ | ✅ | ❌ | 0.12.0 |
|
[
getFreeDiskStorage()
](
#getFreeDiskStorage
)
|
`number`
| ✅ | ✅ | ❌ | 0.15.0 |
|
[
getIPAddress()
](
#getipaddress
)
|
`Promise<string>`
| ❌ | ✅ | ❌ | 0.12.0 |
|
[
getInstanceID()
](
#getinstanceid
)
|
`string`
| ❌ | ✅ | ❌ | ? |
|
[
getLastUpdateTime()
](
#getlastupdatetime
)
|
`number`
| ❌ | ✅ | ❌ | 0.12.0 |
...
...
@@ -208,6 +209,7 @@ var DeviceInfo = require("react-native-device-info");
|
[
getSystemName()
](
#getsystemname
)
|
`string`
| ✅ | ✅ | ✅ | ? |
|
[
getSystemVersion()
](
#getsystemversion
)
|
`string`
| ✅ | ✅ | ✅ | ? |
|
[
getTimezone()
](
#gettimezone
)
|
`string`
| ✅ | ✅ | ✅ | ? |
|
[
getTotalDiskCapacity()
](
#getTotalDiskCapacity
)
|
`number`
| ✅ | ✅ | ❌ | 0.15.0 |
|
[
getTotalMemory()
](
#gettotalmemory
)
|
`number`
| ✅ | ✅ | ❌ | 0.14.0 |
|
[
getUniqueID()
](
#getuniqueid
)
|
`string`
| ✅ | ✅ | ✅ | ? |
|
[
getUserAgent()
](
#getuseragent
)
|
`string`
| ✅ | ✅ | ❌ | 0.7.0 |
...
...
@@ -389,6 +391,22 @@ const firstInstallTime = DeviceInfo.getFirstInstallTime();
---
### getFreeDiskStorage()
Gets available storage size, in bytes
(Android: Returns only available external storage size, not including internal)
**Examples**
```
js
const
freeDiskStorage
=
DeviceInfo
.
getFreeDiskStorage
();
// Android: 17179869184
// iOS: 17179869184
```
---
### getIPAddress()
Gets the device current IP address.
...
...
@@ -597,6 +615,20 @@ Gets the device default timezone.
const
timezone
=
DeviceInfo
.
getTimezone
();
// "Africa/Tunis"
```
---
### getTotalDiskCapacity()
Gets full disk storage size, in bytes
**Examples**
```
js
const
storageSize
=
DeviceInfo
.
getTotalDiskCapacity
();
// Android: 17179869184
// iOS: 17179869184
```
---
### getTotalMemory()
...
...
RNDeviceInfo/RNDeviceInfo.m
View file @
cbbbb159
...
...
@@ -210,10 +210,36 @@ RCT_EXPORT_MODULE(RNDeviceInfo)
return
[
NSProcessInfo
processInfo
].
physicalMemory
;
}
-
(
NSDictionary
*
)
getStorageDictionary
{
NSArray
*
paths
=
NSSearchPathForDirectoriesInDomains
(
NSDocumentDirectory
,
NSUserDomainMask
,
YES
);
return
[[
NSFileManager
defaultManager
]
attributesOfFileSystemForPath
:[
paths
lastObject
]
error
:
nil
];
}
-
(
uint64_t
)
totalDiskCapacity
{
uint64_t
totalSpace
=
0
;
NSDictionary
*
storage
=
[
self
getStorageDictionary
];
if
(
storage
)
{
NSNumber
*
fileSystemSizeInBytes
=
[
storage
objectForKey
:
NSFileSystemSize
];
totalSpace
=
[
fileSystemSizeInBytes
unsignedLongLongValue
];
}
return
totalSpace
;
}
-
(
uint64_t
)
freeDiskStorage
{
uint64_t
freeSpace
=
0
;
NSDictionary
*
storage
=
[
self
getStorageDictionary
];
if
(
storage
)
{
NSNumber
*
freeFileSystemSizeInBytes
=
[
storage
objectForKey
:
NSFileSystemFreeSize
];
freeSpace
=
[
freeFileSystemSizeInBytes
unsignedLongLongValue
];
}
return
freeSpace
;
}
-
(
NSDictionary
*
)
constantsToExport
{
UIDevice
*
currentDevice
=
[
UIDevice
currentDevice
];
NSString
*
uniqueId
=
[
DeviceUID
uid
];
return
@{
...
...
@@ -238,7 +264,9 @@ RCT_EXPORT_MODULE(RNDeviceInfo)
@"isEmulator"
:
@
(
self
.
isEmulator
),
@"isTablet"
:
@
(
self
.
isTablet
),
@"is24Hour"
:
@
(
self
.
is24Hour
),
@"totalMemory"
:
@
(
self
.
totalMemory
)
@"totalMemory"
:
@
(
self
.
totalMemory
),
@"totalDiskCapacity"
:
@
(
self
.
totalDiskCapacity
),
@"freeDiskStorage"
:
@
(
self
.
freeDiskStorage
),
};
}
...
...
android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
View file @
cbbbb159
...
...
@@ -11,6 +11,8 @@ import android.content.res.Configuration;
import
android.net.wifi.WifiManager
;
import
android.net.wifi.WifiInfo
;
import
android.os.Build
;
import
android.os.Environment
;
import
android.os.StatFs
;
import
android.provider.Settings.Secure
;
import
android.webkit.WebSettings
;
import
android.telephony.TelephonyManager
;
...
...
@@ -120,6 +122,18 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
return
telMgr
.
getNetworkOperatorName
();
}
@ReactMethod
public
long
getTotalDiskCapacity
()
{
StatFs
root
=
new
StatFs
(
Environment
.
getRootDirectory
().
getAbsolutePath
());
return
root
.
getBlockCountLong
()
*
root
.
getBlockSizeLong
();
}
@ReactMethod
public
long
getFreeDiskStorage
()
{
StatFs
external
=
new
StatFs
(
Environment
.
getExternalStorageDirectory
().
getAbsolutePath
());
return
external
.
getAvailableBlocksLong
()
*
external
.
getBlockSizeLong
();
}
@Override
public
@Nullable
Map
<
String
,
Object
>
getConstants
()
{
HashMap
<
String
,
Object
>
constants
=
new
HashMap
<
String
,
Object
>();
...
...
@@ -201,6 +215,8 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants
.
put
(
"phoneNumber"
,
telMgr
.
getLine1Number
());
}
constants
.
put
(
"carrier"
,
this
.
getCarrier
());
constants
.
put
(
"totalDiskCapacity"
,
this
.
getTotalDiskCapacity
());
constants
.
put
(
"freeDiskStorage"
,
this
.
getFreeDiskStorage
());
Runtime
rt
=
Runtime
.
getRuntime
();
constants
.
put
(
"maxMemory"
,
rt
.
maxMemory
());
...
...
deviceinfo.d.ts
View file @
cbbbb159
...
...
@@ -33,3 +33,5 @@ export function getAPILevel(): number;
export
function
getCarrier
():
string
;
export
function
getTotalMemory
():
number
;
export
function
getMaxMemory
():
number
;
export
function
getTotalDiskCapacity
():
number
;
export
function
getFreeDiskStorage
():
number
;
\ No newline at end of file
deviceinfo.js
View file @
cbbbb159
...
...
@@ -101,4 +101,10 @@ module.exports = {
getMaxMemory
:
function
()
{
return
RNDeviceInfo
.
maxMemory
;
},
getTotalDiskCapacity
:
function
()
{
return
RNDeviceInfo
.
totalDiskCapacity
;
},
getFreeDiskStorage
:
function
()
{
return
RNDeviceInfo
.
freeDiskStorage
;
}
};
deviceinfo.js.flow
View file @
cbbbb159
...
...
@@ -33,4 +33,6 @@ declare module.exports: {
getCarrier: () => string,
getTotalMemory: () => number,
getMaxMemory: () => number,
getTotalDiskCapacity: () => number,
getFreeDiskStorage: () => number,
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment