gpt4 book ai didi

java - 如何从 Android 应用程序调用电话

转载 作者:行者123 更新时间:2023-12-01 12:44:09 25 4
gpt4 key购买 nike

我正在尝试制作一个带有按钮的应用程序来调用不同的电话号码。我有这个: 包 com.BigTooth.Apps.Recromax;

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 文件中。它告诉我这是不正确的。请帮忙!!!

最佳答案

button.setOnClickListener 位置错误。另外,onClickListener 有点令人困惑。应该是:

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);
}
}

关于java - 如何从 Android 应用程序调用电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24845851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com