You want to open the default Dialer app on a device. What is wrong with this code?

✅  The correct answer is:

  • startActivityWithResult() should be used instead of startActivity() when using Intent.ACTION_DIAL.

Question:

You want to open the default Dialer app on a device. What is wrong with this code?

Solution:

  • startActivityWithResult() should be used instead of startActivity() when using Intent.ACTION_DIAL.
  • For Intent.ACTION_DIAL, the Intent option Intent.FLAG_ACTIVITY_NEW_TASK must be added when using this dialerIntent.
  • The dialerIntent will cause an ActivityNotFoundException to be thrown on devices that do not support Intent.ACTION_DIAL.
  • The permission android.permission.CALL_PHONE must be requested first before Intent.ACTION_DIAL can be used.