我在写一个android2.2版的应用程序时,调用系统的短信功能是出错,
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;public class Activity_02Activity extends Activity {
/** Called when the activity is first created. */
private Button myButton=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton=(Button)findViewById(R.id.myButton);
myButton.setOnClickListener(new MyButtonListener());
}
class MyButtonListener implements android.view.View.OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
//生成一个Intent对象
/*Intent intent=new Intent();
intent.putExtra("textIntent","123");
intent.setClass(Activity_02Activity.this, OtherActivity.class);
Activity_02Activity.this.startActivity(intent);*/
Uri uri=Uri.parse("smstc://0800000123");
Intent intent=new Intent(Intent.ACTION_SEND,uri);
intent.putExtra("sdf", "The SMS text");
startActivity(intent);
}
}
}
如果去掉: Uri uri=Uri.parse("smstc://0800000123");
Intent intent=new Intent(Intent.ACTION_SEND,uri);
intent.putExtra("sdf", "The SMS text");
startActivity(intent);
这些,程序是没有错误的;注释里的能正确运行。一加上上面几行代码程序就意外结束,不知道是何原因啊!!
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;public class Activity_02Activity extends Activity {
/** Called when the activity is first created. */
private Button myButton=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton=(Button)findViewById(R.id.myButton);
myButton.setOnClickListener(new MyButtonListener());
}
class MyButtonListener implements android.view.View.OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
//生成一个Intent对象
/*Intent intent=new Intent();
intent.putExtra("textIntent","123");
intent.setClass(Activity_02Activity.this, OtherActivity.class);
Activity_02Activity.this.startActivity(intent);*/
Uri uri=Uri.parse("smstc://0800000123");
Intent intent=new Intent(Intent.ACTION_SEND,uri);
intent.putExtra("sdf", "The SMS text");
startActivity(intent);
}
}
}
如果去掉: Uri uri=Uri.parse("smstc://0800000123");
Intent intent=new Intent(Intent.ACTION_SEND,uri);
intent.putExtra("sdf", "The SMS text");
startActivity(intent);
这些,程序是没有错误的;注释里的能正确运行。一加上上面几行代码程序就意外结束,不知道是何原因啊!!
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", "信息内容");
startActivity(intent);
这种吧
Intent intent =new Intent(Intent.ACTION_SENDTO,uri);
intent.putExtra("sms_body", "Hello World!");
startActivity(intent);