two ways to write it:
1st non static
public class Util {
Context context;
public Util(Context context) {
this.context = context;
}
public String imei() {
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
return telephonyManager.getDeviceId();
}
}
and then in onCreate
method
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Util u = new Util(this);
String test = u.imei();
}
2nd static
public class Util {
public static String imei(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
return telephonyManager.getDeviceId();
}
}
and then in onCreate
method
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String test = Util.imei(this);
}