我正在尝试向手机发送 SMS,但我遇到了一个问题:我无法收到消息,但模拟器告诉我消息已发送。
这是我的代码,
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.telephony.SmsManager;
import android.view.View.OnClickListener;
import android.widget.Toast;
import android.view.View;
public class sendsms extends Activity {
Button buttonSend;
EditText textPhoneNo;
EditText textSMS;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sending);
buttonSend = (Button) findViewById(R.id.BTNSENDSMS);
textPhoneNo = (EditText) findViewById(R.id.txtEnterNoSMS);
textSMS = (EditText) findViewById(R.id.txtMsgSMS);
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String phoneNo = textPhoneNo.getText().toString();
String sms = textSMS.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),"SMS faild, please try again later!",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
}
}
还有我的 AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sdc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="12" />
<uses-permission android:name="android.permission.SEND_SMS" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>