0

I want to open a Calling Screen Directly from my app, I searched a lot about on internet and getting no success. Code i am following to call a number from android app is as follows :

startActivity(new Intent(Intent.ACTION_CALL).setData(Uri.parse("tel:" + phoneNo)));

in Manifest :

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

but this code is showing Choose Action Window and I don't want to show this window :

enter image description here

Is it possible to open Phone call app directly rather than open Action Window ?

Vishal Chhodwani
  • 2,567
  • 5
  • 27
  • 40
Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
  • http://stackoverflow.com/a/26783528/2308683 – OneCricketeer Jan 20 '17 at 13:39
  • 1
    "I don't want to show this window" -- first, what if the user wants to use Skype? Second, there are ~2 billion Android devices, from thousands of device models, and manufacturers can replace "Phone call app". How do you intend to identify "Phone call app" from any other `ACTION_CALL` handler? – CommonsWare Jan 20 '17 at 13:40
  • @CommonsWare i am working on a app from which user will be able to call on number if he tap on a widget , dont want skype call as a option. – Kapil Rajput Jan 20 '17 at 13:43
  • 1
    @KapilRajput Some people use Skype for regular calls.. – creativecreatorormaybenot Jan 20 '17 at 13:54
  • 1
    You as the developer shouldn't decide what the user wants. Say you run your app on a tablet. It has no phone app, but what if Skype is installed there and the user has no other option? – OneCricketeer Jan 20 '17 at 13:55
  • @creativecreatorormaybenot my question is not to show skype as a option like for an example if user want to call on dominos or any other number where there is no role of skype call then why to show him skype as a option ? – Kapil Rajput Jan 23 '17 at 05:03
  • @cricket_007 my question is not to show skype as a option like for an example if user want to call on dominos or any other number where there is no role of skype call then why to show him skype as a option ? – Kapil Rajput Jan 23 '17 at 05:03
  • Skype only appears because it's installed. Test your app on an emulator or different device – OneCricketeer Jan 23 '17 at 13:02
  • @KapilRajput Because Skype allows **phone calls**. https://www.skype.com/en/features/call-phones-and-mobiles/ – creativecreatorormaybenot Jan 23 '17 at 15:22

2 Answers2

1

Unfortunately (or really not) you can't. This is security measure. You can't directly open some app, because in 70% cases (just my results after testing) it will give you Security error.

Some clarification

As mentioned in comments you can define package in Intent. But it's really unhealthy behavior. For example

    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
    sendIntent.setType("message/rfc822");
    sendIntent.setData(Uri.parse("test@gmail.com"));
    sendIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
    sendIntent.putExtra(Intent.EXTRA_EMAIL, getSelectedContactsEmails().toArray());
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, "subj");
    sendIntent.putExtra(Intent.EXTRA_TEXT, "text");
    startActivityForResult(sendIntent,0);

This code will call directly GMail app. But it have unpredictable behavior . In my case I got crash on one Nexus 5, but all worked on another one. Also you need to add additional code to ensure, that package is installed.

In your case you need to call some phone app. Do you know Android device fragmentation? There are 10000+ different devices and all of them can have different packages for calling. So do you really need it?

In fact there is even special method, that will handle selection of app you need by system

startActivity(Intent.createChooser(emailIntent, "Send mail via ...")); //example

This code won't get you Security error ever, because user actions are perceived by system "as a truth"

Clarification 2

Yes, you can cycle through all packages that can accept your intent. Yes, you can even call random(or pre-defined) package and yes, it might work is some cases. But some doesn't mean all and there is a problem. And if there any chance that app will crash on some device, you need to avoid it by any means.

Ekalips
  • 1,473
  • 11
  • 20
0

you can set a package name for your intent and directly call an application

intent.setPackage("com.android.phone");               
nariman amani
  • 263
  • 6
  • 21