我的短信应用程序正在从android工作室开始工作,当它从手机生成时,无法接收任何消息,我的样本联系电话号码“+639123456789”(菲律宾电话号码)。从Android工作室,我使用的数字是5554,它的工作原理,可以收到消息。
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText num = findViewById(R.id.e1);
final EditText mes = findViewById(R.id.e2);
Button btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
btnSendSMS.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try{
String S1 = num.getText().toString();
String S2 = mes.getText().toString();
sendSMS(S1,S2);}
catch (Exception e){
Toast.makeText(MainActivity.this,e+" & ",Toast.LENGTH_SHORT).show();
Log.e("Error: ", String.valueOf(e));
}
/*here i can send message to emulator 5556. In Real device
*you can change number*/
}
});
}
private void sendSMS(String phoneNumber, String message) {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
}}
的AndroidManifest.xml
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
04-27 15:40:36.728 6258-6258 / com.example.coorsdev.textmessage E / Error :: java.lang.IllegalArgumentException:无效的destinationAddress