<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hello"
android:sharedUserId="android.uid.phone"
android:versionCode="1"
android:versionName="100">
android:process="com.android.phone"
android:label="@string/app_name">
<activity android:name=".HelloWordActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
{
mSmscHandle = new Handler(this);
getSmsc();
* 本方法需要使用到两个隐藏类
* com.android.internal.telephony.PhoneFactory
* com.android.internal.telephony.Phone
*/
@SuppressWarnings("unchecked")
public void getSmsc()
{
try
{
//调用PhoneFactory.getDefaultPhone()
Class PhoneFactory = Class.forName("com.android.internal.telephony.PhoneFactory");
Method getDefaultPhone = PhoneFactory.getMethod("getDefaultPhone", (Class[]) null);
Object phone = (Object)getDefaultPhone.invoke(null, (Object[]) null);
Log.i("HELLOWORLD", "phone:" + phone);
//调用Phone.getSmscAddress(Message result)
Class[] ParamType = new Class[1];
ParamType[0] = Message.class;
Message msg = mSmscHandle.obtainMessage(10001);
Object[] paramValue = new Object[1];
paramValue[0] = msg;
Class Phone = Class.forName("com.android.internal.telephony.Phone");
Method getSmscAddress = Phone.getDeclaredMethod("getSmscAddress", ParamType);
getSmscAddress.invoke(phone, paramValue);
}
catch( Exception e )
{
showTrace(e);
}
}
{
// TODO Auto-generated method stub
/**
* 收到短信中心号
* sg.obj 为AsyncResult的实例对象
*/
Log.i("HELLOWORLD", "handleMessage() msg.what:" + msg.what
+ " data:" + msg.peekData()
+ " result:" + msg.obj.toString());
if(10001 == msg.what)
{
dealSmscResult(msg.obj);
}
return false;
}
{
try
{
Field exception = asyncResult.getClass().getDeclaredField("exception");
Throwable throwable = (Throwable)exception.get(asyncResult);
Field result = asyncResult.getClass().getDeclaredField("result");
Object myResult = result.get(asyncResult);
if(null != myResult)
{
Log.i("HELLOWORLD", "dealSmscResult() result:" + myResult.toString());
String szResult = (String)myResult;
String szAddr = szResult.split(",")[0];
Log.i("HELLOWORLD", "dealSmscResult() smsc:" + szAddr);
}
if(null != throwable)
{
Log.i("HELLOWORLD", "dealSmscResult() throwable:" + throwable.getMessage());
}
}
catch(Exception e)
{
showTrace(e);
}
}

yefei92214 2012-10-22
yefei92214 2012-10-22