I know it was very simple to do it but I come across a very strange issue. I have to call Police in danger Situation by just tapping a button. So I have used following code to call.
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:100"));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(callIntent);
Added CALL_PHONE
permission in AndroidManifest.xml
. The Issue is that it is opening the 100 on Dial Pad but not making call directly. I want that to happen immediately when user clicks on the button.
When I tried to to put +91 before 100 it is calling the number automatically but why plus is required for such numbers. So Someone help me how to solve this issue
There could be a problem that the android system doesnt recognize
100
as a valid phone number, instead if you put the country code before it then it works fine. TO solve such issue take a look at this library libnhonenumber. You could use it something like thisA Long time passed. But may help someone else. If you want to call directly, you should use requestPermissions method.
1. Add this line to your manifest file:
2. Define a class variable in the activity class:
3. Add these lines to the onCreate method of the activity:
4. And for making a call immediately after clicking on Allow button, override onRequestPermissionsResult method:
When a user give the permission, next time there will be no dialogue box and call will be make directly.
Best way to directly call without user intervention..
There are two intents to call/start calling: ACTION_CALL and ACTION_DIAL. ACTION_DIAL will only open the dialer with the number filled in, but allows the user to actually call or reject the call. ACTION_CALL will immediately call the number and requires an extra permission. So make sure you have the permission
From the documentation of
ACTION_CALL
:So it seems this behavior is on purpose.