我使發送短信的功能變得簡單。如何使用sendTextMessage發送短信
public void send(String address, String packet){//address="13614951242" packet="a"
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(address, null, packet, null, null);
}
但是,有NullPointException錯誤。
10-12 03:20:05.463: ERROR/AndroidRuntime(9662): Caused by: java.lang.NullPointerException
10-12 03:20:05.463: ERROR/AndroidRuntime(9662): at android.os.Parcel.readException(Parcel.java:1253)
10-12 03:20:05.463: ERROR/AndroidRuntime(9662): at android.os.Parcel.readException(Parcel.java:1235)
10-12 03:20:05.463: ERROR/AndroidRuntime(9662): at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:561)
10-12 03:20:05.463: ERROR/AndroidRuntime(9662): at android.telephony.SmsManager.sendTextMessage(SmsManager.java:109)
10-12 03:20:05.463: ERROR/AndroidRuntime(9662): at ric.FPSProject.SinglePos.SinglePosMap.initPersonData(SinglePosMap.java:260)
10-12 03:20:05.463: ERROR/AndroidRuntime(9662): at ric.FPSProject.SinglePos.SinglePosMap.onResume(SinglePosMap.java:160)
10-12 03:20:05.463: ERROR/AndroidRuntime(9662): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1151)
10-12 03:20:05.463: ERROR/AndroidRuntime(9662): at android.app.Activity.performResume(Activity.java:3823)
10-12 03:20:05.463: ERROR/AndroidRuntime(9662): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3123)
10-12 03:20:05.463: ERROR/AndroidRuntime(9662): ... 12 more
怎麼了?幫我!
您能否給我們提供一些更多信息?有關此錯誤的logcat輸出中是否還有其他內容? –
這是在手機上運行SMS功能,正確嗎? – MrZander
檢查此鏈接:http://stackoverflow.com/questions/7832864/sendtextmessage-in-android-phone – Pradeep