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
8cd63a9a
Commit
8cd63a9a
authored
Mar 14, 2018
by
Nicolas
Committed by
Mehdi Achour
Mar 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add getInstallReferrer() for Android (#344)
parent
d59cbe7e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
0 deletions
+58
-0
README.md
README.md
+16
-0
AndroidManifest.xml
android/src/main/AndroidManifest.xml
+11
-0
RNDeviceModule.java
...c/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
+7
-0
RNDeviceReceiver.java
...main/java/com/learnium/RNDeviceInfo/RNDeviceReceiver.java
+20
-0
deviceinfo.js
deviceinfo.js
+3
-0
index.js
web/index.js
+1
-0
No files found.
README.md
View file @
8cd63a9a
...
...
@@ -209,6 +209,7 @@ var DeviceInfo = require('react-native-device-info');
|
[
getFontScale()
](
#getfontscale
)
|
`number`
| ✅ | ✅ | ❌ | 0.15.0 |
|
[
getFreeDiskStorage()
](
#getfreediskstorage
)
|
`number`
| ✅ | ✅ | ❌ | 0.15.0 |
|
[
getIPAddress()
](
#getipaddress
)
|
`Promise<string>`
| ❌ | ✅ | ❌ | 0.12.0 |
|
[
getInstallReferrer()
](
#getinstallreferrer
)
|
`string`
| ❌ | ✅ | ❌ | 0.19.0 |
|
[
getInstanceID()
](
#getinstanceid
)
|
`string`
| ❌ | ✅ | ❌ | ? |
|
[
getLastUpdateTime()
](
#getlastupdatetime
)
|
`number`
| ❌ | ✅ | ❌ | 0.12.0 |
|
[
getMACAddress()
](
#getmacaddress
)
|
`Promise<string>`
| ❌ | ✅ | ❌ | 0.12.0 |
...
...
@@ -480,6 +481,21 @@ DeviceInfo.getIPAddress().then(ip => {
---
### getInstallReferrer
Gets the referrer string upon application installation.
**Examples**
```
js
const
referrer
=
DeviceInfo
.
getInstallReferrer
();
// If the app was installed from https://play.google.com/store/apps/details?id=com.myapp&referrer=my_install_referrer
// the result will be "my_install_referrer"
```
---
### getInstanceID()
Gets the application instance ID.
...
...
android/src/main/AndroidManifest.xml
View file @
8cd63a9a
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"com.learnium.RNDeviceInfo"
>
<application>
<receiver
android:name=
"com.learnium.RNDeviceInfo.RNDeviceReceiver"
android:enabled=
"true"
android:exported=
"true"
>
<intent-filter>
<action
android:name=
"com.android.vending.INSTALL_REFERRER"
/>
</intent-filter>
</receiver>
</application>
</manifest>
android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
View file @
8cd63a9a
...
...
@@ -4,6 +4,7 @@ import android.Manifest;
import
android.app.KeyguardManager
;
import
android.bluetooth.BluetoothAdapter
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.pm.PackageInfo
;
...
...
@@ -207,6 +208,11 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
p
.
resolve
(
batteryLevel
);
}
public
String
getInstallReferrer
()
{
SharedPreferences
sharedPref
=
getReactApplicationContext
().
getSharedPreferences
(
"react-native-device-info"
,
Context
.
MODE_PRIVATE
);
return
sharedPref
.
getString
(
"installReferrer"
,
null
);
}
@Override
public
@Nullable
Map
<
String
,
Object
>
getConstants
()
{
...
...
@@ -291,6 +297,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants
.
put
(
"carrier"
,
this
.
getCarrier
());
constants
.
put
(
"totalDiskCapacity"
,
this
.
getTotalDiskCapacity
());
constants
.
put
(
"freeDiskStorage"
,
this
.
getFreeDiskStorage
());
constants
.
put
(
"installReferrer"
,
this
.
getInstallReferrer
());
Runtime
rt
=
Runtime
.
getRuntime
();
constants
.
put
(
"maxMemory"
,
rt
.
maxMemory
());
...
...
android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceReceiver.java
0 → 100644
View file @
8cd63a9a
package
com
.
learnium
.
RNDeviceInfo
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences.Editor
;
public
class
RNDeviceReceiver
extends
BroadcastReceiver
{
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
String
action
=
intent
.
getAction
();
if
(
action
.
equals
(
"com.android.vending.INSTALL_REFERRER"
))
{
SharedPreferences
sharedPref
=
context
.
getSharedPreferences
(
"react-native-device-info"
,
Context
.
MODE_PRIVATE
);
SharedPreferences
.
Editor
editor
=
sharedPref
.
edit
();
editor
.
putString
(
"installReferrer"
,
intent
.
getStringExtra
(
"referrer"
));
editor
.
commit
();
}
}
}
deviceinfo.js
View file @
8cd63a9a
...
...
@@ -94,6 +94,9 @@ module.exports = {
getFirstInstallTime
:
function
()
{
return
RNDeviceInfo
.
firstInstallTime
;
},
getInstallReferrer
:
function
()
{
return
RNDeviceInfo
.
installReferrer
;
},
getLastUpdateTime
:
function
()
{
return
RNDeviceInfo
.
lastUpdateTime
;
},
...
...
web/index.js
View file @
8cd63a9a
...
...
@@ -30,6 +30,7 @@ module.exports = {
is24Hour
:
false
,
isPinOrFingerprintSet
:
callback
=>
callback
&&
callback
(
false
),
firstInstallTime
:
0
,
installReferrer
:
''
,
lastUpdateTime
:
0
,
phoneNumber
:
''
,
carrier
:
''
,
...
...
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