我有一个触发Call Intent的ImageButton。我想知道是否可以传递2个数字作为数据,这样当你点击按钮时,它会自动打开一个弹出窗口,让你选择要拨打的号码。这应该是您的联系人的默认Android行为,如果您有多个与您尝试呼叫的联系人关联的号码,它会为您提供选项。
我的代码是这样的:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("1234567890"));
startActivity(callIntent);
我尝试将多个号码分成半冒号,但不起作用:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("1234567890;0987654321"));
startActivity(callIntent);
有人有解决方案吗?
由于 曼努埃尔
答案 0 :(得分:0)
我不认为会以编程方式退出任何此类内容。
但你可以试试这样的事情,点击图片按钮:
1)如果只有1个号码,请使用您编写的代码。
2)如果有多个号码,请打开一个对话框(您需要自己创建所有这些)并让用户选择号码,然后将号码重定向到您的代码
答案 1 :(得分:0)
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MainActivity extends AppCompatActivity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
attachUi();
//getPattern();
}
private void attachUi() {
tv = (TextView) findViewById(R.id.textview);
tv.setOnClickListener(clk);
}
private View.OnClickListener clk = new View.OnClickListener() {
@Override
public void onClick(View view) {
gotoCall();
}
};
private void gotoCall() {
ArrayList<String> list = new ArrayList<String>();
list.add("08698511503");
list.add("07666175151");
list.add("0548554552");
TelephonyManager TelephonyMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
TelephonyMgr.listen(new PhoneCallListener(this, list), PhoneStateListener.LISTEN_CALL_STATE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
//startActivity(callIntent);
}
}
// create new class
class PhoneCallListener extends PhoneStateListener {
int count = 0;
Context context;
ArrayList<String> list;
public PhoneCallListener(MainActivity mainActivity, ArrayList<String> list) {
this.context = mainActivity;
this.list = list;
}
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
Log.v(this.getClass().getSimpleName(), "List Size ::" + list);
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Log.v(this.getClass().getSimpleName(), "Inside Ringing State::");
break;
case TelephonyManager.CALL_STATE_IDLE:
String phone_number = null;
Log.v(this.getClass().getSimpleName(), "Inside Idle State::");
if (list.size() > count) {
phone_number = list.get(count);
count++;
}
if (phone_number != null) {
nextCalling(phone_number);
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.v(this.getClass().getSimpleName(), "Inside OFFHOOK State::");
break;
default:
break;
}
}
private void nextCalling(String phone_number) {
Intent callIntent1 = new Intent(Intent.ACTION_CALL);
callIntent1.setData(Uri.parse("tel:" + phone_number));
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
context.startActivity(callIntent1);
}
}
// in manifest add permission..
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />