Categories
Android

PhoneFactory.getDefaultPhone must be called from Looper thread

写了一个设置、显示本机号码的小工具(A small tool displays and settings my phone number),详见”Android设置显示本机号码“。照着Settings写的,运行时,遇到了:
1487 AndroidRuntime E Caused by: java.lang.RuntimeException: PhoneFactory.getDefaultPhone must be called from Looper thread
1487 AndroidRuntime E at com.android.internal.telephony.PhoneFactory.getDefaultPhone(PhoneFactory.java:155)
1487 AndroidRuntime E ... 24 more

目前好像除了PhoneApp,其他应用程序是无法调用
com.android.internal.telephony.Phone;
com.android.internal.telephony.PhoneFactory
的,一般是通过发intent消息。仔细对比了一下,发现Settings的AndroidManifest.xml用到Phone的Activity属性添加了:

android:process="com.android.phone"

在AndroidManifest.xml 把android:sharedUserId=”android.uid.system”也加上,问题解决。像CM的固件, 编译的时候,android.uid.system 是 Android 默认的公共签名。如果使用android.uid.system的apk签名不不一样,是不能装的,会报错:ERROR/PackageManager(81): Package org.lytsing.myphonenumber has no signatures that match those in shared user android.uid.system; ignoring!

当然,android手机第三方开发者不能用这个方法。网上还有其他一些解决办法,参看:
http://stackoverflow.com/questions/2143754/can-a-telephony-phone-object-be-instantiated-through-the-sdk 原理是通过AIDL及反射机制,使用隐藏API。

If you enjoyed this post, make sure you subscribe to my RSS feed!

3 replies on “PhoneFactory.getDefaultPhone must be called from Looper thread”

Hi, thanks for the hints. After following your steps, I can make the apk run on the emulator. But it cannot be installed on a real device. Could you show any light? Does it mean the device must be rooted? Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *