简体   繁体   中英

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. Now when user clicked on a textview I want to display alerdialog with all those numbers in listview. 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. When user pressed on Textview dialog box is appearing with numbers in a listview. 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

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

I was calling startActivity(launchIntent ) after alertDialog.show(); so because of that I was getting that warning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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