It is necessary to call the dialer from the application with a pre-specified number. I use the code:

String number = "tel:+7123456789"; Intent callIntent = new Intent(Intent.ACTION_DIAL, Uri.parse(number)); startActivity(callIntent); 

The last line is highlighted in red. How to fix? And what markup is needed in the layout to display a button with a call?

  • You need to put the cursor on the red balun in the ruler on the left and read the error message. For the button with a call, you can use any markup that you like. - Enikeyschik

1 answer 1

startActivity() is a method of the Activity class, that is, you need an instance of this class - if you just need a variable with the Activity type, in a particular case it can be this , if the launch occurs inside the Activity :

 Activity myActivity; //бла-бла String number = "tel:+7123456789"; Intent callIntent = new Intent(Intent.ACTION_DIAL, Uri.parse(number)); myActivity.startActivity(callIntent); 

To select in the form of markup, you can simply use:

 <TextView android:id="@+id/myId" android:text="tel:+7123456789" android:autolink="phone"/>