我在android活动中创建了2个按钮,这些按钮与不同的类相关联,每个类有4到5个按钮,每个按钮都被编码用于向特定的人发送消息。但是当我在我的设备上运行它时,应用程序崩溃了。
这是我的代码:
callButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + telephone-number));
startActivity(i);
}
});
有人能告诉我应用程序崩溃的原因吗?
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
Button z = (Button) findViewById(R.id.button1);
z.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View l) {
// TODO Auto-generated method stub
String messageToSend = "Come Out Bro....";
String fnumber = "03339579504";
SmsManager.getDefault().sendTextMessage(fnumber, null, messageToSend, null,null);
}
});
Button x = (Button) findViewById(R.id.button2);
x.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View y) {
// TODO Auto-generated method stub
String messageSend = "Come Out Bro....";
String snumber = "03339023418";
SmsManager.getDefault().sendTextMessage(snumber, null, messageSend, null,null);
}
});
Button c = (Button) findViewById(R.id.butt4);
c.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View u) {
// TODO Auto-generated method stub
String ToSend = "Come Out Bro....";
String anumber = "03443444720";
SmsManager.getDefault().sendTextMessage(anumber, null, ToSend, null,null);
}
});
Button v = (Button) findViewById(R.id.butt5);
v.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View i) {
// TODO Auto-generated method stub
String kmessageToSend = "Come Out Bro....";
String knumber = "03139644916";
SmsManager.getDefault().sendTextMessage(knumber, null, kmessageToSend, null,null);
}
});
Button b = (Button) findViewById(R.id.butt6);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View o) {
// TODO Auto-generated method stub
String almessageToSend = "Come Out Bro....";
String alnumber = "03451923255";
SmsManager.getDefault().sendTextMessage(alnumber, null, almessageToSend, null,null);
}
});
Button n = (Button) findViewById(R.id.butt3);
n.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View p) {
// TODO Auto-generated method stub
String zamessageToSend = "Come Out Bro....";
String zanumber = "03015932300";
SmsManager.getDefault().sendTextMessage(zanumber, null, zamessageToSend, null,null);
}
});
}
}
答案 0 :(得分:0)
您是否在Manifest中添加了权限?
添加此项以拨打电话并发送消息 -
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS"/>
如果您有更多按钮执行此类操作,则必须先在Manifest中添加权限。