| 16279 |
manas |
1 |
package com.saholic.profittill.Utils;
|
|
|
2 |
|
|
|
3 |
import android.content.Context;
|
|
|
4 |
import android.content.pm.PackageInfo;
|
|
|
5 |
import android.content.pm.PackageManager;
|
|
|
6 |
import android.net.ConnectivityManager;
|
|
|
7 |
import android.net.NetworkInfo;
|
|
|
8 |
import android.os.Build;
|
|
|
9 |
import android.telephony.TelephonyManager;
|
|
|
10 |
import android.util.DisplayMetrics;
|
|
|
11 |
|
|
|
12 |
import com.google.android.gms.common.ConnectionResult;
|
|
|
13 |
import com.google.android.gms.common.GooglePlayServicesUtil;
|
|
|
14 |
|
|
|
15 |
import java.util.HashMap;
|
|
|
16 |
import java.util.Map;
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* Created by kshitij on 24/7/15.
|
|
|
20 |
*/
|
|
|
21 |
public class AnalyticsUtility {
|
|
|
22 |
public static String getImeiNumber(Context context){
|
|
|
23 |
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
24 |
return telephonyManager.getDeviceId();
|
|
|
25 |
}
|
|
|
26 |
public static String getNetworkOperatorName(Context context){
|
|
|
27 |
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
28 |
return telephonyManager.getNetworkOperatorName();
|
|
|
29 |
}
|
|
|
30 |
public static String getNetworkOperator(Context context){
|
|
|
31 |
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
32 |
return telephonyManager.getNetworkOperator();
|
|
|
33 |
}
|
|
|
34 |
public static String checkGooglePlayServices(Context context){
|
|
|
35 |
if(ConnectionResult.SUCCESS== GooglePlayServicesUtil.isGooglePlayServicesAvailable(context)){
|
|
|
36 |
return "available";
|
|
|
37 |
}else{
|
|
|
38 |
return "error" + GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public static String getAppVersionCode(Context c){
|
|
|
43 |
String appVersion;
|
|
|
44 |
try {
|
|
|
45 |
PackageManager manager = c.getPackageManager();
|
|
|
46 |
PackageInfo info = manager.getPackageInfo(c.getPackageName(), 0);
|
|
|
47 |
appVersion=info.versionCode+"";
|
|
|
48 |
}catch (PackageManager.NameNotFoundException pm){
|
|
|
49 |
appVersion=null;
|
|
|
50 |
}
|
|
|
51 |
return appVersion;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
public static String getAppVersionName(Context c){
|
|
|
55 |
String appVersion;
|
|
|
56 |
try {
|
|
|
57 |
PackageManager manager = c.getPackageManager();
|
|
|
58 |
PackageInfo info = manager.getPackageInfo(c.getPackageName(), 0);
|
|
|
59 |
appVersion=info.versionName+"";
|
|
|
60 |
}catch (PackageManager.NameNotFoundException pm){
|
|
|
61 |
appVersion=null;
|
|
|
62 |
}
|
|
|
63 |
return appVersion;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
public static boolean checkWifi(Context context){
|
|
|
67 |
boolean checkWifi;
|
|
|
68 |
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
69 |
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
|
|
70 |
if (mWifi==null){
|
|
|
71 |
checkWifi= Boolean.parseBoolean(null);
|
|
|
72 |
}else {
|
| 21178 |
rajender |
73 |
checkWifi = mWifi.isConnected();
|
| 16279 |
manas |
74 |
}
|
|
|
75 |
return checkWifi;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
public static int getOsVersion(){
|
|
|
79 |
return android.os.Build.VERSION.SDK_INT;
|
|
|
80 |
}
|
|
|
81 |
public static String getManufacturer(){
|
|
|
82 |
return Build.MANUFACTURER;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
public static String getBrand(){
|
|
|
86 |
return Build.BRAND;
|
|
|
87 |
}
|
|
|
88 |
public static String getModel(){
|
|
|
89 |
return Build.MODEL;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
public static int getHeight(Context c){
|
|
|
94 |
DisplayMetrics metrics = c.getResources().getDisplayMetrics();
|
|
|
95 |
return metrics.heightPixels;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
public static int getwidth(Context c){
|
|
|
99 |
DisplayMetrics metrics = c.getResources().getDisplayMetrics();
|
|
|
100 |
return metrics.widthPixels;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
public static String getProperties(Context c){
|
|
|
106 |
StringBuilder properties = new StringBuilder();
|
|
|
107 |
properties.append("{");
|
|
|
108 |
properties.append("'Imei Number':'"+UtilityFunctions.getImeiNumber(c)+"'");
|
|
|
109 |
properties.append(",'Version Code':'" + AnalyticsUtility.getAppVersionCode(c)+"'");
|
|
|
110 |
properties.append(",'Version Name':'" + AnalyticsUtility.getAppVersionName(c)+"'");
|
|
|
111 |
properties.append(",'Os Version':'"+AnalyticsUtility.getOsVersion()+"'");
|
|
|
112 |
properties.append(",'Manufacturer':'"+AnalyticsUtility.getManufacturer()+"'");
|
|
|
113 |
properties.append(",'Brand':'"+AnalyticsUtility.getBrand()+"'");
|
|
|
114 |
properties.append(",'Model':'"+AnalyticsUtility.getModel()+"'");
|
|
|
115 |
properties.append(",'WiFi':'" + AnalyticsUtility.checkWifi(c)+"'");
|
|
|
116 |
properties.append(",'Google Play Services':'" + AnalyticsUtility.checkGooglePlayServices(c)+"'");
|
|
|
117 |
properties.append(",'Operator Name':'" + AnalyticsUtility.getNetworkOperatorName(c)+"'");
|
|
|
118 |
properties.append(",'Operator Type':'" + AnalyticsUtility.getNetworkClass(c)+"'");
|
|
|
119 |
properties.append(",'Height':'" + AnalyticsUtility.getHeight(c)+"'");
|
|
|
120 |
properties.append(",'Width':'" + AnalyticsUtility.getwidth(c)+"'");
|
|
|
121 |
properties.append("}");
|
|
|
122 |
return properties.toString();
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
public static String getNetworkClass(Context context) {
|
|
|
126 |
TelephonyManager mTelephonyManager = (TelephonyManager)
|
|
|
127 |
context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
128 |
int networkType = mTelephonyManager.getNetworkType();
|
|
|
129 |
switch (networkType) {
|
|
|
130 |
case TelephonyManager.NETWORK_TYPE_GPRS:
|
|
|
131 |
case TelephonyManager.NETWORK_TYPE_EDGE:
|
|
|
132 |
case TelephonyManager.NETWORK_TYPE_CDMA:
|
|
|
133 |
case TelephonyManager.NETWORK_TYPE_1xRTT:
|
|
|
134 |
case TelephonyManager.NETWORK_TYPE_IDEN:
|
|
|
135 |
return "2G";
|
|
|
136 |
case TelephonyManager.NETWORK_TYPE_UMTS:
|
|
|
137 |
case TelephonyManager.NETWORK_TYPE_EVDO_0:
|
|
|
138 |
case TelephonyManager.NETWORK_TYPE_EVDO_A:
|
|
|
139 |
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
|
|
140 |
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
|
|
141 |
case TelephonyManager.NETWORK_TYPE_HSPA:
|
|
|
142 |
case TelephonyManager.NETWORK_TYPE_EVDO_B:
|
|
|
143 |
case TelephonyManager.NETWORK_TYPE_EHRPD:
|
|
|
144 |
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
|
|
145 |
return "3G";
|
|
|
146 |
case TelephonyManager.NETWORK_TYPE_LTE:
|
|
|
147 |
return "4G";
|
|
|
148 |
default:
|
|
|
149 |
return "Unknown";
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
public static Map<String,String> getAnalyticsRequest(Context c, String user_id,String category,String action,String label){
|
|
|
155 |
Map<String,String> analyticsRequest=new HashMap<>();
|
|
|
156 |
analyticsRequest.put("user_id", user_id);
|
|
|
157 |
analyticsRequest.put("category", category);
|
|
|
158 |
analyticsRequest.put("action", action);
|
|
|
159 |
analyticsRequest.put("label", label);
|
|
|
160 |
analyticsRequest.put("properties", getProperties(c));
|
|
|
161 |
return analyticsRequest;
|
|
|
162 |
}
|
|
|
163 |
}
|