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
b7c5a33e
Unverified
Commit
b7c5a33e
authored
Mar 07, 2018
by
Mehdi Achour
Committed by
GitHub
Mar 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(android): fix Android > 6 compatibility for getMacAddress() (#349)
parent
81b0c20f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
1 deletion
+35
-1
RNDeviceModule.java
...c/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
+35
-1
No files found.
android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
View file @
b7c5a33e
...
@@ -26,11 +26,14 @@ import com.facebook.react.bridge.ReactMethod;
...
@@ -26,11 +26,14 @@ import com.facebook.react.bridge.ReactMethod;
import
com.facebook.react.bridge.Callback
;
import
com.facebook.react.bridge.Callback
;
import
com.facebook.react.bridge.Promise
;
import
com.facebook.react.bridge.Promise
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.TimeZone
;
import
java.util.TimeZone
;
import
java.lang.Runtime
;
import
java.lang.Runtime
;
import
java.net.NetworkInterface
;
import
javax.annotation.Nullable
;
import
javax.annotation.Nullable
;
...
@@ -130,7 +133,38 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
...
@@ -130,7 +133,38 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
@ReactMethod
@ReactMethod
public
void
getMacAddress
(
Promise
p
)
{
public
void
getMacAddress
(
Promise
p
)
{
String
macAddress
=
getWifiInfo
().
getMacAddress
();
String
macAddress
=
getWifiInfo
().
getMacAddress
();
p
.
resolve
(
macAddress
);
String
permission
=
"android.permission.INTERNET"
;
int
res
=
this
.
reactContext
.
checkCallingOrSelfPermission
(
permission
);
if
(
res
==
PackageManager
.
PERMISSION_GRANTED
)
{
try
{
List
<
NetworkInterface
>
all
=
Collections
.
list
(
NetworkInterface
.
getNetworkInterfaces
());
for
(
NetworkInterface
nif
:
all
)
{
if
(!
nif
.
getName
().
equalsIgnoreCase
(
"wlan0"
))
continue
;
byte
[]
macBytes
=
nif
.
getHardwareAddress
();
if
(
macBytes
==
null
)
{
macAddress
=
""
;
}
else
{
StringBuilder
res1
=
new
StringBuilder
();
for
(
byte
b
:
macBytes
)
{
res1
.
append
(
String
.
format
(
"%02X:"
,
b
));
}
if
(
res1
.
length
()
>
0
)
{
res1
.
deleteCharAt
(
res1
.
length
()
-
1
);
}
macAddress
=
res1
.
toString
();
}
}
}
catch
(
Exception
ex
)
{
}
}
p
.
resolve
(
macAddress
);
}
}
@ReactMethod
@ReactMethod
...
...
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