Android sendTextMessage不适用
我正在尝试构建一个通过短信发送gps位置的应用程序,但我遇到了以下错误: SmsManager类型中的方法sendTextMessage(String、String、String、PendingEvent、PendingEvent)不适用于参数(EditText、null、String、null、null)Android sendTextMessage不适用,android,Android,我正在尝试构建一个通过短信发送gps位置的应用程序,但我遇到了以下错误: SmsManager类型中的方法sendTextMessage(String、String、String、PendingEvent、PendingEvent)不适用于参数(EditText、null、String、null、null) package com.example.thermolocation;导入android.app.Activity; 导入android.app.pendingent; 导入android.
package com.example.thermolocation;导入android.app.Activity;
导入android.app.pendingent;
导入android.content.Context;
导入android.content.Intent;
导入android.location.location;
导入android.location.LocationListener;
导入android.telephony.gsm.smsmsmanager;
导入android.util.Log;
导入android.location.LocationManager;
导入android.os.Bundle;
导入android.widget.EditText;
导入android.widget.Toast;
公共类MainActivity扩展了活动
{
EditText txtphoneNo;
字符串文本;
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*使用LocationManager类获取GPS位置*/
LocationManager mlocManager=(LocationManager)getSystemService(Context.LOCATION\u服务);
LocationListener mlocListener=新建MyLocationListener();
mlocManager.RequestLocationUpdate(LocationManager.GPS_提供程序,0,0,mlocListener);
}
/*类我的位置侦听器*/
公共类MyLocationListener实现LocationListener
{
@凌驾
位置更改后的公共无效(位置loc)
{
loc.getLatitude();
loc.getLongitude();
Text=“我的位置是:”+
“Latitude=“+loc.getLatitude()+
“Longitude=“+loc.getLongitude();
Toast.makeText(getApplicationContext(),Text,Toast.LENGTH_SHORT).show();
txtphoneNo=(EditText)findViewById(R.id.editTextPhoneNo);
sendSMSMessage();
}
受保护的void sendSMSMessage(){
Log.i(“发送短信”,“发送短信”);
试一试{
android.telephony.smsmsmanager smsmsmanager=android.telephony.smsmsmanager.getDefault();
smsManager.sendTextMessage(txtphoneNo,null,Text,null,null);/*错误非常明显:
方法是:
sendTextMessage(字符串、字符串、字符串、PendingEvent、PendingEvent)
但您使用参数(EditText,null,String,null,null)调用它。
请注意,第一个参数是一个EditText
,而不是一个String
(它想要的)
您应该使用txtphoneNo.getText().toString()
检查您的错误
:
The method sendTextMessage(String, String, String, PendingIntent, PendingIntent) in the type SmsManager is not applicable for the arguments (EditText, null, String, null, null)
第一个参数不匹配,您传递的是EditText而不是字符串。
我建议您更改如下:
smsManager.sendTextMessage(txtphoneNo.getText().toString(), null, Text, null, null);
smsManager.sendTextMessage(txtphoneNo.getText().toString(), null, Text, null, null);
EditText不是字符串。请将调用更改为:
smsManager.sendTextMessage(txtphoneNo.getText().toString(), null, Text, null, null);