3

我有一个触发呼叫意图的 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);

有人对此有解决方案吗?

谢谢曼努埃尔

4

2 回答 2

0

我不认为以编程方式退出任何这样的事情。

但是你可以尝试这样的事情,点击图像按钮:

1)如果只有1个数字,请使用您编写的代码。

2)如果有多个号码,打开一个对话框(您需要自己创建)并让用户选择号码,然后将号码重定向到您的代码

于 2012-09-24T07:10:15.427 回答
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" />
于 2016-07-26T11:37:35.833 回答