如何制作一个android应用程序,它可以发送短信到内置的特定号码
我已经做了一些编码,但它不是我想要的工作。我想,将有一个预定义的文本(“你好”)在程序和用户只能在编辑文本输入后缀消息。联系人号码应已在程序中预定义。在前端,应该只显示一个编辑文本字段,用户可以在其中输入消息并单击发送,然后消息将发送到带有前缀“hello”的特定默认号码。请看我的代码,并建议我如何才能做到这一点如何制作一个android应用程序,它可以发送短信到内置的特定号码,android,Android,我已经做了一些编码,但它不是我想要的工作。我想,将有一个预定义的文本(“你好”)在程序和用户只能在编辑文本输入后缀消息。联系人号码应已在程序中预定义。在前端,应该只显示一个编辑文本字段,用户可以在其中输入消息并单击发送,然后消息将发送到带有前缀“hello”的特定默认号码。请看我的代码,并建议我如何才能做到这一点 import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.ap
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Button btnSendSMS;
EditText enteredNum;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
btnSendSMS.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
enteredNum = (EditText) findViewById(R.id.enterDetail);
sendSMS("+9151222", "HELLO "+ enteredNum);
}
});
}
private void sendSMS(String phoneNumber, String message)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
}
}
在按钮的onClick处理程序中将
enteredNum
更改为enteredNum.getText().toString()
btnSendSMS.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
enteredNum = (EditText) findViewById(R.id.enterDetail);
sendSMS("+9151222", "HELLO "+ enteredNum.getText().toString());
}
});
您当前的输出是什么?您可以尝试sendSMS(“+9151222”,“HELLO”+enteredNum.getText().toString());我希望您已声明允许在清单文件中发送短信。有什么问题吗?错误或输出错误?解释一下please@AyushMaharjan谢谢你兄弟谢谢你这工作做得很好。你能告诉我如何在我的应用程序中显示从这个号码收到的信息吗?