简体   繁体   English

无法从AlertDialog拨打号码

[英]Not able to dial number from AlertDialog

I want to give a choice to user for selecting a number for dialing. 我想给用户一个选择拨号号码的选择。 In my case I have textview which contains some phone numbers and I collected those numbers in array. 就我而言,我有包含一些电话号码的textview,我将这些号码收集在数组中。 Now when user clicked on a textview I want to display alerdialog with all those numbers in listview. 现在,当用户单击文本视图时,我想在列表视图中显示带有所有这些数字的alerdialog。 I am able to do all above things but problem is when user clicks on particular telephone numebr of dialog box call application is not launching. 我能够做上述所有事情,但是问题是当用户单击对话框调用应用程序的特定电话号码时,它没有启动。 I used below code: 我用下面的代码:

 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Choose Number")
           .setItems(phones, new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int phNo) {
            // TODO Auto-generated method stub
            launchIntent = new Intent(Intent.ACTION_DIAL);
            launchIntent.setData(Uri.parse("tel:" + phones[phNo]));
            startActivity(launchIntent);

        }

     }); 

     AlertDialog alertDialog = builder.create();            
     alertDialog.show();

The above code is inside textview. 上面的代码在textview内部。 When user pressed on Textview dialog box is appearing with numbers in a listview. 当用户按下Textview时,在列表视图中将显示带有数字的对话框。 When I selected any numbers and clicked it is giving me below warning and not able to call application. 当我选择任何数字并单击时,它在警告下方出现,并且无法调用应用程序。

attempted to finish an input event but the input event receiver has already been disposed.

How can I resolve my issue? 我该如何解决我的问题? Thanks in advance, regards! 在此先感谢,问候!

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Choose Number")
       .setItems(phones, new DialogInterface.OnClickListener(){
        @Override
        public void onClick(DialogInterface dialog, int phNo) {
        // TODO Auto-generated method stub
        launchIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phones[phNo]));
        startActivity(launchIntent);
    }

 }); 

 AlertDialog alertDialog = builder.create();            
 alertDialog.show();

Add this permission in AndroidManifest.xml 在AndroidManifest.xml中添加此权限

<uses-permission android:name="android.permission.CALL_PHONE" />

I was calling startActivity(launchIntent ) after alertDialog.show(); 我在alertDialog.show();之后调用了startActivity(launchIntent alertDialog.show(); so because of that I was getting that warning. 因此正因为如此,我得到了警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM