Udanesh N
Udanesh N

Reputation: 171

Make a call in android that does not have an activity

I made an android app to call to a number when a message is received using broadcast receiver. But I am getting an error no activity found to handle the intent. How can I solve this problem?

Code is given below

Intent intent1 = new Intent(Intent.ACTION_CALL);
intent1.setData(Uri.parse(incno1));
context.startActivity(intent1);

I added the line intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);, but this also does not solve my problem.

Upvotes: 1

Views: 127

Answers (4)

Desu
Desu

Reputation: 464

    try {
          Intent intent = new Intent(Intent.ACTION_CALL);
          intent.setData(Uri.parse("tel:+123456"));
          startActivity(intent);
        } catch (Exception e) {
          Log.e("SampleApp", "Failed to invoke call", e);
        }

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

use permission in AndroidManifest.xml

Upvotes: 0

sarabu
sarabu

Reputation: 521

You can add it in your xml file

        android:autoLink="phone"
        android:phoneNumber="true"

add this to your text view that links directly to call.

Upvotes: 0

Stack Overflow User
Stack Overflow User

Reputation: 4082

Try this code may be working i am not tested:

    Intent intent1 = new Intent(Intent.ACTION_CALL);
    intent1.setData(Uri.parse("tel:" + incno1));
    intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent1.addFlags(Intent.FLAG_FROM_BACKGROUND);
    context.startActivity(intent1);

Upvotes: 0

S.A.Norton Stanley
S.A.Norton Stanley

Reputation: 1873

The protocol is incorrect. You need to do the following:

  callIntent.setData(Uri.parse("tel:"+incno1));

And ensure the following permission is set:

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

Upvotes: 1

Related Questions