android中的android.telephony.TelephonyManager这个类可以获得手机的串号和手机号等信息。
现在我想重写这个类。我在我的应用中创建了相同路径名的类(android.telephony.TelephonyManager)
然后从android.jar中把这个类反编译出来了,但反编译的结果好像是错误的:
public class TelephonyManager {
TelephonyManager() {
throw new RuntimeException("Stub!");
}
public String getDeviceSoftwareVersion() {
throw new RuntimeException("Stub!");
}
public String getDeviceId() {
throw new RuntimeException("Stub!");
}
public CellLocation getCellLocation() {
throw new RuntimeException("Stub!");
}
public List getNeighboringCellInfo() {
throw new RuntimeException("Stub!");
}
public int getPhoneType() {
throw new RuntimeException("Stub!");
}
.
.
.
}
并且把这个类改成我要的效果后,重新生成apk后好像也没有生效 。结果还是没变。
请问有谁遇到相似的问题没
这个类首先你是可以拿到源码的,不需要反编译。对应的路径如下。另外,从这个类的实现来看是可以进行重写,但是在telephony下是需要对应的读取权限的,而且这些类是在Phone进程中的,是在开机的时候就已经被加载到后台一直运行的,因为这其中有很多东西在开机的时候就需要读取、使用。所以重写应该是存在问题。
frameworks\base\telephony\java\android\telephony\TelephonyManager.java
public class TelephonyManager {
private static final String TAG = "TelephonyManager";
private Context mContext;
private ITelephonyRegistry mRegistry;
/** @hide */
public TelephonyManager(Context context) {
mContext = context;
mRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
"telephony.registry"));
}
/** @hide */
private TelephonyManager() {
}
private static TelephonyManager sInstance = new TelephonyManager();
/** @hide */
public static TelephonyManager getDefault() {
return sInstance;
}