[英]How to implement image button to call (no phone number input editText) in android?
I'm new new to java programming and this website. 我是Java编程和此网站的新手。 it's my 2nd program but I'm stuck with calling, sending SMS, emailing, showing location using google map.
这是我的第二个程序,但是我仍然无法使用Google地图打电话,发送短信,发送电子邮件,显示位置。 I'm using imageButtons for all of these.
我正在为所有这些使用imageButtons。 User doesn't need to type any numbers or addresses(not using editText to get user input) For example, it makes calls when user click on Phone icon.
用户不需要键入任何数字或地址(不使用editText来获取用户输入),例如,当用户单击“电话”图标时,它将进行呼叫。 However, I still need a user input(the actual msg not the destination number or email address) for sending sms and email.
但是,我仍然需要用户输入(实际的味精而不是目的地号码或电子邮件地址)来发送短信和电子邮件。 I can do if I use editText but can't do without using editText.
我可以使用editText来做,但是不能不使用editText来做。 How do I do this?
我该怎么做呢?
My wrong code: 我的错误代码:
public class PhoneActivity extends Activity {
ImageButton btnphonecall;
String phoneNumber = "091111111";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_phone);
btnphonecall=(ImageButton)findViewById(R.id.imageButton1);
btnphonecall.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(Intent.ACTION_CALL);
i.setData(Uri.parse("091111111"));
PhoneActivity.this.startActivity(i);
}
});
}
Instead of this 代替这个
PhoneActivity.this.startActivity(i);
Try this 尝试这个
startActivity(i);
You don't have any PhoneActivity in your code. 您的代码中没有任何PhoneActivity。
Also add this permission in your manifest file 还要在清单文件中添加此权限
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.