Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lib_base
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sikang
lib_base
Commits
d6ee3c0e
Commit
d6ee3c0e
authored
Apr 01, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add device uuid
parent
e751e5f2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
2 deletions
+124
-2
src/main/AndroidManifest.xml
+1
-0
src/main/java/tech/starwin/utils/context_utils/AppInfoUtils.java
+109
-0
src/main/java/tech/starwin/utils/context_utils/PermissionsHelper.java
+5
-2
src/main/java/tech/starwin/utils/format_utils/StringFormat.java
+9
-0
No files found.
src/main/AndroidManifest.xml
View file @
d6ee3c0e
...
...
@@ -14,6 +14,7 @@
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<!--<uses-permission android:name="android.permission.READ_PHONE_STATE" />-->
<uses-permission
android:name=
"android.permission.READ_PHONE_STATE"
/>
<uses-permission
android:name=
"android.permission.WAKE_LOCK"
/>
<application>
...
...
src/main/java/tech/starwin/utils/context_utils/AppInfoUtils.java
View file @
d6ee3c0e
...
...
@@ -5,21 +5,29 @@ import android.annotation.SuppressLint;
import
android.content.Context
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.os.Environment
;
import
android.provider.Settings
;
import
android.support.v4.app.ActivityCompat
;
import
android.telephony.TelephonyManager
;
import
android.text.TextUtils
;
import
android.util.Base64
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.UUID
;
import
tech.starwin.utils.LogUtils
;
import
tech.starwin.utils.PreferencesManager
;
import
tech.starwin.utils.format_utils.StringFormat
;
/**
* Created by SiKang on 2018/12/10.
*/
public
class
AppInfoUtils
{
public
static
final
String
TAG
=
"AppInfoUtils_LOG"
;
/**
* 获取应用程序名称
...
...
@@ -53,6 +61,59 @@ public class AppInfoUtils {
/**
* 在SD卡中保存一个设备标识
*/
public
static
String
saveDeviceUUID
()
{
String
uuid
=
UUID
.
randomUUID
().
toString
();
try
{
File
dir
=
new
File
(
Environment
.
getExternalStorageDirectory
()
+
"/star_system/"
);
if
(!
dir
.
exists
()){
dir
.
mkdirs
();
}
File
file
=
new
File
(
dir
.
getAbsolutePath
()+
"/device.json"
);
if
(!
file
.
exists
()){
file
.
createNewFile
();
}
FileWriter
fw
=
new
FileWriter
(
file
.
getAbsoluteFile
());
fw
.
flush
();
fw
.
write
(
Base64
.
encodeToString
(
uuid
.
getBytes
(),
Base64
.
DEFAULT
));
fw
.
close
();
}
catch
(
IOException
e
)
{
LogUtils
.
i
(
TAG
,
"getDeviceUUID: "
+
e
.
getMessage
());
e
.
printStackTrace
();
}
LogUtils
.
i
(
TAG
,
"saveDeviceUUID: "
+
uuid
);
return
uuid
;
}
public
static
String
getDeviceUUID
()
{
try
{
File
file
=
new
File
(
Environment
.
getExternalStorageDirectory
()
+
"/star_system/"
+
"/device.json"
);
if
(!
file
.
exists
()){
return
""
;
}
FileReader
fd
=
new
FileReader
(
file
.
getAbsolutePath
());
char
[]
chs
=
new
char
[
1024
];
while
(
fd
.
read
(
chs
)
!=
-
1
)
{
String
str
=
String
.
valueOf
(
chs
);
String
uuid
=
new
String
(
Base64
.
decode
(
str
.
getBytes
(),
Base64
.
DEFAULT
));
LogUtils
.
i
(
TAG
,
"getDeviceUUID: "
+
uuid
);
return
uuid
;
}
}
catch
(
FileNotFoundException
e
)
{
LogUtils
.
i
(
TAG
,
"getDeviceUUID: "
+
e
.
getMessage
());
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
LogUtils
.
i
(
TAG
,
"getDeviceUUID: "
+
e
.
getMessage
());
e
.
printStackTrace
();
}
return
""
;
}
/**
* 判断是否存在某个包且可获取入口
*/
public
static
boolean
isPackageExist
(
Context
context
,
String
packageName
)
{
...
...
@@ -71,6 +132,54 @@ public class AppInfoUtils {
return
false
;
}
/**
* 获取手机IMEI
*
* @param context
* @return
*/
public
static
final
String
getIMEI
(
Context
context
)
{
try
{
if
(
ActivityCompat
.
checkSelfPermission
(
context
,
Manifest
.
permission
.
READ_PHONE_STATE
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
return
""
;
}
//实例化TelephonyManager对象
TelephonyManager
telephonyManager
=
(
TelephonyManager
)
context
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
);
//获取IMEI号
String
imei
=
telephonyManager
.
getDeviceId
();
//在次做个验证,也不是什么时候都能获取到的啊
if
(
imei
==
null
)
{
imei
=
""
;
}
return
imei
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
""
;
}
}
/**
* 获取手机IMSI
*/
public
static
String
getIMSI
(
Context
context
)
{
try
{
if
(
ActivityCompat
.
checkSelfPermission
(
context
,
Manifest
.
permission
.
READ_PHONE_STATE
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
return
""
;
}
TelephonyManager
telephonyManager
=
(
TelephonyManager
)
context
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
);
//获取IMSI号
String
imsi
=
telephonyManager
.
getSubscriberId
();
if
(
null
==
imsi
)
{
imsi
=
""
;
}
return
imsi
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
""
;
}
}
// @SuppressLint("MissingPermission")
// public static String getPhoneNumber(Context context) {
...
...
src/main/java/tech/starwin/utils/context_utils/PermissionsHelper.java
View file @
d6ee3c0e
...
...
@@ -52,9 +52,12 @@ public class PermissionsHelper {
* 需要收集隐私数据时的必要权限
*/
public
static
String
[]
MUST_PERMISSIONS
=
new
String
[]{
Manifest
.
permission
.
READ_CONTACTS
,
Manifest
.
permission
.
READ_CALL_LOG
,
Manifest
.
permission
.
READ_SMS
,
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
ACCESS_COARSE_LOCATION
,
//粗精度定位
Manifest
.
permission
.
ACCESS_FINE_LOCATION
//卫星定位
// Manifest.permission.READ_PHONE_STATE
...
...
@@ -67,6 +70,8 @@ public class PermissionsHelper {
Manifest
.
permission
.
READ_CONTACTS
,
// Manifest.permission.READ_CALL_LOG,
// Manifest.permission.READ_SMS,
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
ACCESS_COARSE_LOCATION
,
//粗精度定位
Manifest
.
permission
.
ACCESS_FINE_LOCATION
//卫星定位
// Manifest.permission.READ_PHONE_STATE
...
...
@@ -77,8 +82,6 @@ public class PermissionsHelper {
*/
public
static
String
[]
CAMERA
=
new
String
[]{
Manifest
.
permission
.
CAMERA
,
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
RECORD_AUDIO
};
...
...
src/main/java/tech/starwin/utils/format_utils/StringFormat.java
View file @
d6ee3c0e
...
...
@@ -140,6 +140,15 @@ public class StringFormat {
else
return
""
;
}
/**
* base64 解码
*/
public
static
String
fromBase64
(
String
value
)
{
if
(!
TextUtils
.
isEmpty
(
value
))
return
new
String
(
Base64
.
decode
(
value
.
getBytes
(),
Base64
.
DEFAULT
));
else
return
""
;
}
/**
* String转base64
...
...
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