-1

In my case in need give 10 mobile number as input to start a phone intent

Here is my code

    public void dialPhone(View view) {

    Intent intent = new Intent(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel:" + phoneNumber));
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }

Please help me .I am just a beginner so please give me somewhat detailed answer

  • 1
    Why would you ever want to use a **numeric** type? A **string** will do, in this case. Unless you don't want to do **math** with a phone number. In which case, a **long** would do the trick (the max value for an int is 2^31 - 1). – Phantômaxx May 08 '17 at 15:34
  • I had tried "long" and "Biginteger".Still getting the same error " integer value is too long – Abdul Waajid May 08 '17 at 15:57
  • 1
    Maybe you didn't try the most logical thing: **string**. – Phantômaxx May 08 '17 at 15:59

1 Answers1

1

You are getting the error integer is too long error because in Java, the int data type specifies a 32 bit integer, and thus is limited to the minimum and maximum values of -2 147 483 648 and +2 147 483 647 respectively. (See this for more details)

Your phone number most likely exceeds this range of int data type. For this particular problem, you can (and probably should) use the String class for phoneNumber, as that is what the documentation specifies:

Uri parse (String uriString)

Thus, modify your code to make phoneNumber a String object, and it should work without any errors.

Community
  • 1
  • 1
aksh1618
  • 2,245
  • 18
  • 37