首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从android应用程序拨打电话

如何从android应用程序拨打电话
EN

Stack Overflow用户
提问于 2014-07-20 07:15:00
回答 1查看 49关注 0票数 0

我正在尝试制作一款带有按钮的应用程序,可以呼叫不同的电话号码。我有这个: package com.BigTooth.Apps.Recromax;

代码语言:javascript
复制
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.Intent;
import android.content.*;
import android.net.Uri;
import android.view.View.OnClickListener;


public class MainActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    private void phoneCall1()
    {
        String phoneCallUri = "tel:4078421430";
        Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
        phoneCallIntent.setData(Uri.parse(phoneCallUri));
        startActivity(phoneCallIntent);
    }
    // add button listener
    button.setOnClickListener(new OnClickListener() {
    private void phoneCall()
    {
        String phoneCallUri = "tel:8889807091";
        Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
        phoneCallIntent.setData(Uri.parse(phoneCallUri));
        startActivity(phoneCallIntent);}
    } 
}

在我的MainActivity.java文件中。它告诉我这是不正确的。请帮帮我!

EN

Stack Overflow用户

发布于 2014-07-20 07:22:54

button.setOnClickListener出现在错误的位置。而且,onClickListener有点让人头疼。应该是:

代码语言:javascript
复制
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.Intent;
import android.content.*;
import android.net.Uri;
import android.view.View.OnClickListener;


public class MainActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button button = (Button) findViewById(R.id.youButtonId);
        Button button1 = (Button) findViewById(R.id.youButtonId1);
        // add button listener
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                phoneCall();
            }
        });
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                phoneCall1();
            }
        });
    }
    private void phoneCall()
    {
        String phoneCallUri = "tel:8889807091";
        Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
        phoneCallIntent.setData(Uri.parse(phoneCallUri));
        startActivity(phoneCallIntent);
    }
    private void phoneCall1()
    {
        String phoneCallUri = "tel:4078421430";
        Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
        phoneCallIntent.setData(Uri.parse(phoneCallUri));
        startActivity(phoneCallIntent);
    }
}
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24845851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档