Skip to content

Commit d478ce7

Browse files
committed
some code
1 parent 38dee03 commit d478ce7

File tree

5 files changed

+185
-70
lines changed

5 files changed

+185
-70
lines changed

Diff for: ExLibrary/build.gradle

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies {
1010
compile 'com.android.support:design:24+'
1111
// Viewpager指示器
1212
compile 'fr.baloomba:viewpagerindicator:2.4.2'
13-
compile 'com.jakewharton:butterknife:7.0.1'
13+
compile 'com.jakewharton:butterknife:8.4.0'
1414
compile 'org.greenrobot:eventbus:3+'
1515
//图片缓存
1616
compile 'com.facebook.fresco:fresco:0.11.0'
@@ -23,24 +23,24 @@ dependencies {
2323
compile 'com.facebook.fresco:imagepipeline-volley:0.11.0'
2424
compile 'com.facebook.fresco:stetho:0.11.0'
2525
// Google
26-
compile 'com.google.code.gson:gson:2.6'
26+
compile 'com.google.code.gson:gson:2.7'
2727
compile 'com.alibaba:fastjson:1.2.5'
2828
//Volley+OkHttp
29-
// compile 'com.squareup.okio:okio:1.5.0'
29+
// compile 'com.squareup.okio:okio:1.5.0'
3030
//compile 'com.squareup.okhttp3:okhttp:3.2.0'
3131
// ReactiveX
32-
compile 'io.reactivex:rxjava:1.1.5'
32+
compile 'io.reactivex:rxjava:1.1.9'
3333
compile 'io.reactivex:rxandroid:1.2.0'
34+
compile 'io.reactivex.rxjava2:rxandroid:2.0.0-RC1'
3435
// retrofit
3536
compile 'com.squareup.retrofit:retrofit:2+'
3637
compile 'com.squareup.retrofit:converter-gson:2+'
3738
compile 'com.squareup.retrofit:adapter-rxjava:2+'
38-
3939
//Umeng
40-
4140
//compile 'com.umeng.analytics:analytics:latest.integration'
4241
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
4342
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'
43+
4444
}
4545

4646

Diff for: ExLibrary/src/main/java/com/androidex/activity/ExFragment.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import org.greenrobot.eventbus.EventBus;
1414

15-
import butterknife.ButterKnife;
1615

1716

1817
/**
@@ -36,7 +35,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
3635

3736
mRootView = inflater.inflate(setFragmentContentView(), container, false);
3837

39-
ButterKnife.bind(this, mRootView);
38+
4039
return mRootView;
4140
}
4241

@@ -60,7 +59,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
6059

6160
@Override public void onDestroyView() {
6261
super.onDestroy();
63-
ButterKnife.unbind(this);
6462
}
6563

6664

+172-55
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,197 @@
11
package com.androidex.utils;
22

33
import android.content.Context;
4+
import android.net.wifi.WifiInfo;
5+
import android.net.wifi.WifiManager;
46
import android.provider.Settings;
57
import android.telephony.TelephonyManager;
6-
import android.text.*;
78

89
import com.androidex.context.ExApplication;
910

11+
import java.io.File;
12+
import java.io.FileOutputStream;
13+
import java.io.IOException;
14+
import java.io.RandomAccessFile;
1015
import java.net.Inet4Address;
1116
import java.net.InetAddress;
1217
import java.net.NetworkInterface;
1318
import java.util.Enumeration;
19+
import java.util.UUID;
1420

1521
/**
1622
* 设备硬件相关信息
1723
*/
1824
public class DeviceUtil {
1925

20-
/**
21-
* 判断是否有电话功能
22-
*
23-
* @return true:有电话功能
24-
* false:没有电话功能
25-
*/
26-
public static boolean hasPhone() {
27-
28-
TelephonyManager telephony = (TelephonyManager) ExApplication.getContext().
29-
getSystemService(Context.TELEPHONY_SERVICE);
30-
return telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE ? false : true;
31-
}
32-
33-
/**
34-
* 获取手机的IMEI
35-
*/
36-
public static String getIMEI() {
37-
38-
String imei = "";
39-
try {
40-
Context ctx = ExApplication.getContext();
41-
TelephonyManager telephonyManager =
42-
(TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
43-
if (telephonyManager != null) {
44-
45-
imei = telephonyManager.getDeviceId();
46-
if (android.text.TextUtils.isEmpty(imei)) {
47-
imei = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID);
26+
private static String sID = null;
27+
private static final String INSTALLATION = "INSTALLATION";
28+
29+
/**
30+
* 判断是否有电话功能
31+
* android.permission.READ_PHONE_STATE
32+
*
33+
* @return true:有电话功能
34+
* false:没有电话功能
35+
*/
36+
public static boolean hasPhone() {
37+
38+
TelephonyManager telephony = (TelephonyManager) ExApplication.getContext().
39+
getSystemService(Context.TELEPHONY_SERVICE);
40+
return telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE ? false : true;
41+
}
42+
43+
/**
44+
* 获取手机的IMEI
45+
* android.permission.READ_PHONE_STATE
46+
* 1)非手机设备: 如果只带有Wifi的设备或者音乐播放器没有通话的硬件功能的话就没有这个DEVICE_ID
47+
* 2)权限: 获取DEVICE_ID需要READ_PHONE_STATE权限,但如果我们只为了获取它,没有用到其他的通话功能,那这个权限有点大才小用
48+
* 3)bug:在少数的一些手机设备上,该实现有漏洞,会返回垃圾,如:zeros(全是0)或者asterisks(星号)的产品
49+
*/
50+
public static String getIMEI() {
51+
52+
String imei = "";
53+
try {
54+
Context ctx = ExApplication.getContext();
55+
TelephonyManager telephonyManager =
56+
(TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
57+
if (telephonyManager != null) {
58+
59+
imei = telephonyManager.getDeviceId();
60+
if (imei == null) imei = "";
61+
}
62+
} catch (Exception e) {
63+
e.printStackTrace();
4864
}
4965

50-
if (imei == null) imei = "";
51-
}
52-
} catch (Exception e) {
53-
e.printStackTrace();
66+
return imei;
5467
}
5568

56-
return imei;
57-
}
58-
59-
/**
60-
* 获取手机IP地址
61-
*/
62-
private String getPhoneIP() {
63-
try {
64-
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
65-
en.hasMoreElements(); ) {
66-
NetworkInterface intf = en.nextElement();
67-
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();
68-
enumIpAddr.hasMoreElements(); ) {
69-
InetAddress inetAddress = enumIpAddr.nextElement();
70-
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
71-
return inetAddress.getHostAddress().toString();
72-
}
69+
70+
/**
71+
* ANDROID_ID是设备第一次启动时产生和存储的64bit的一个数,当设备被wipe后该数重置ANDROID_ID似乎是获取Device ID的一个好选择,
72+
* <p>
73+
* 但它也有缺陷:
74+
* 1)它在Android <=2.1 or Android >=2.3的版本是可靠、稳定的,但在2.2的版本并不是100%可靠的
75+
* 2)在主流厂商生产的设备上,有一个很经常的bug,就是每个设备都会产生相同的ANDROID_ID:9774d56d682e549c
76+
* 3)厂商定制系统的Bug:有些设备返回的值为null。
77+
* 4)设备差异:对于CDMA设备,ANDROID_ID和TelephonyManager.getDeviceId() 返回相同的值。
78+
*
79+
* @return
80+
*/
81+
public static String getAndroidId() {
82+
83+
String androidId = "";
84+
try {
85+
Context ctx = ExApplication.getContext();
86+
androidId = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID);
87+
} catch (Exception e) {
88+
e.printStackTrace();
89+
}
90+
return androidId;
91+
}
92+
93+
/**
94+
* 获取手机IP地址
95+
*/
96+
public static String getPhoneIP() {
97+
try {
98+
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
99+
en.hasMoreElements(); ) {
100+
NetworkInterface intf = en.nextElement();
101+
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();
102+
enumIpAddr.hasMoreElements(); ) {
103+
InetAddress inetAddress = enumIpAddr.nextElement();
104+
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
105+
return inetAddress.getHostAddress().toString();
106+
}
107+
}
108+
}
109+
} catch (Exception e) {
110+
e.printStackTrace();
111+
}
112+
return "";
113+
}
114+
115+
116+
/**
117+
* 获取MAC地址
118+
* android.permission.ACCESS_WIFI_STATE
119+
* 1)硬件限制:并不是所有的设备都有Wifi和蓝牙硬件,硬件不存在自然也就得不到这一信息。
120+
* 2)获取的限制:如果Wifi没有打开过,是无法获取其Mac地址的;而蓝牙是只有在打开的时候才能获取到其Mac地址。
121+
*
122+
* @param mContext
123+
* @return
124+
*/
125+
public static String getMacAddress(Context mContext) {
126+
String macStr = "";
127+
try {
128+
WifiManager wifiManager = (WifiManager) mContext
129+
.getSystemService(Context.WIFI_SERVICE);
130+
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
131+
if (wifiInfo.getMacAddress() != null) {
132+
macStr = wifiInfo.getMacAddress();// MAC地址
133+
}
134+
} catch (Exception e) {
135+
e.printStackTrace();
73136
}
74-
}
75-
} catch (Exception e) {
76-
e.printStackTrace();
137+
return macStr;
77138
}
78-
return "";
79-
}
139+
140+
/**
141+
* Sim Serial Number
142+
* 装有SIM卡的设备,可以通过下面的方法获取到Sim Serial Number:
143+
*/
144+
public static String getSimSerialNumber() {
145+
146+
String ssNumber = "";
147+
try {
148+
Context ctx = ExApplication.getContext();
149+
TelephonyManager telephonyManager =
150+
(TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
151+
if (telephonyManager != null) {
152+
153+
ssNumber = telephonyManager.getSimSerialNumber();
154+
if (ssNumber == null) ssNumber = "";
155+
}
156+
} catch (Exception e) {
157+
e.printStackTrace();
158+
}
159+
return ssNumber;
160+
}
161+
162+
163+
/**
164+
* 获取设备的UUID
165+
*
166+
* @param context
167+
* @return
168+
*/
169+
public synchronized static String getUUID(Context context) {
170+
if (sID == null) {
171+
File installation = new File(context.getFilesDir(), INSTALLATION);
172+
try {
173+
if (!installation.exists()) writeInstallationFile(installation);
174+
sID = readInstallationFile(installation);
175+
} catch (Exception e) {
176+
throw new RuntimeException(e);
177+
}
178+
}
179+
return sID;
180+
}
181+
182+
private static String readInstallationFile(File installation) throws IOException {
183+
RandomAccessFile f = new RandomAccessFile(installation, "r");
184+
byte[] bytes = new byte[(int) f.length()];
185+
f.readFully(bytes);
186+
f.close();
187+
return new String(bytes);
188+
}
189+
190+
private static void writeInstallationFile(File installation) throws IOException {
191+
FileOutputStream out = new FileOutputStream(installation);
192+
String id = UUID.randomUUID().toString();
193+
out.write(id.getBytes());
194+
out.close();
195+
}
196+
80197
}

Diff for: build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.0'
8+
classpath 'com.android.tools.build:gradle:2.2.2'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
@@ -20,9 +20,9 @@ allprojects {
2020

2121

2222
ext {
23-
compileSdkVersion = 23 //基于哪个SDK编译,这里是API LEVEL
24-
buildToolsVersion = '23.0.3' //基于哪个构建工具版本进行构建的。
25-
targetSdkVersion = 23
23+
compileSdkVersion = 24 //基于哪个SDK编译,这里是API LEVEL
24+
buildToolsVersion = '24.0.0' //基于哪个构建工具版本进行构建的。
25+
targetSdkVersion = 24
2626
minSdkVersion = 21 //5.0 +
2727

2828
versionCode = 1

Diff for: gradle/wrapper/gradle-wrapper.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Apr 27 15:02:54 CST 2016
1+
#Sat Oct 22 16:12:02 CST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

0 commit comments

Comments
 (0)