0

I have two activities in my project in the first activity I have 1 Edittext , and from the second activity I want to dial (Call) the number that was written in the first activity.

Cœur
  • 37,241
  • 25
  • 195
  • 267

3 Answers3

0

If you want to create an EditText, which will call the value in the EditText, use an intent with ACTION_DIAL, to handle the call, in place of opening a new activity.

The following link may be useful:

how to make phone call using intent in android?

Community
  • 1
  • 1
Ben S
  • 33
  • 8
0

Ben S's answer is the right answer if you want to use the default Dialer app on the phone.

But if you want to pass the value of the EditText to your own Activity, just launch an Intent and pass the number as an extra of this Intent:

intent.putExtra("EXTRA_NUMBER", numberAsAString);
David Ferrand
  • 5,357
  • 1
  • 33
  • 43
0

To transfer data from activity1 to activity2, you need to add it as an extra in the intent object.

Do this in activity1 to start activity2 :

final Intent intent = new Intent(this, myActivity2.class);
intent.putExtra("phone_number",((EditText)findViewById(R.id.edttxt_input)).getText().toString());
startActivity(intent);

Then in activity2's onCreate(), do this :

String phoneNumber = getIntent().getStringExtra("phone_number");
String uri = "tel:" + phoneNumber;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);
faizal
  • 3,497
  • 7
  • 37
  • 62
  • when i press the call button the application is stopped – AbdullahADhaim Jul 04 '14 at 16:30
  • Providing more details like the logcat would be immensely more helpful. Have you added the permission in the manifest : `` – faizal Jul 04 '14 at 16:33
  • can you share the error from logcat? And i hope you replaced `edttxt_input` with the id of your `EditText` element defined in the layout file. – faizal Jul 04 '14 at 16:37
  • eclipse.buildId=v22.6.2-1085508 java.version=1.7.0_51 java.vendor=Oracle Corporation BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_GB Framework arguments: -product com.android.ide.eclipse.adt.package.product Command-line arguments: -os win32 -ws win32 -arch x86_64 -product com.android.ide.eclipse.adt.package.product Warning Fri Jul 04 05:20:01 AST 2014 activity_main.xml: "" in attribute "textSize" is not a valid format. – AbdullahADhaim Jul 04 '14 at 16:48
  • Then it's really not the same source of error. Check your XML layout file activity_main.xml, you probably have written `android:textSize=""` which is not valid. But as this is just a warning probably you also have another true error in LogCat. – David Ferrand Jul 04 '14 at 18:20