简体   繁体   English

如何在Android中实现图片按钮通话(无电话号码输入editText)?

[英]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.

相关问题 如何借助android studio中的按钮拨打edittext中给出的电话号码? - How can I call the phone number given in the edittext with the help of a button in android studio? (EditText)Android联系人列表获取电话号码 - (EditText)Android Contact list getting phone number 如何在Android中单击按钮时添加未知数量的edittext - How to add unknown number of edittext on button click in android android中没有重复项的输入类型的EditText - EditText of input type with number of no duplicates in android 如何编写电话号码以在android中拨打电话但不拨打电话 - How to write a phone number for calling in android but not make the call 单击按钮按电话号码呼叫(java) - call by phone number on button click (java) 如何使按钮将EditText输入添加到Listview - How To Make Button Add EditText Input to a Listview 来自来电的电话号码无法正常工作 - phone number from incoming call not working android 使用android拨打电话而无需离开应用 - Call a phone number with android without leaving app 如何在前一个屏幕android中使用给定输入数字的edittext,textview和图像创建动态布局? - How to create dynamic layout with edittext , textview and images with given input number in previous screen android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM