简体   繁体   中英

How to make an emergency call directly from default phone dialer without any user interaction in Android?

I have a requirement in my app that I need to call the Police directly without any user interaction in an emergency situation. According to the Android documentation,

Applications can dial emergency numbers using ACTION_DIAL

So I have used the ACTION_DIAL intent as below:

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:+91100"));
startActivity(intent);

But instead of calling +91100 directly, in some devices the dialer screen is shown with the number prepopulated and we need to click on the Call icon to make the call and in some other devices it asks me to choose from which app I would like to make the call. I would like the call to be made directly from the default Phone Dialer without any user interaction since this call will be made when the user is an emergency situation.

Could you please let me know if there is any way in which this can be achieved?

Thank you.

You need the special CALL_PRIVLIDGED permission. However this permission is a system level permission, accessible only if pre-installed or on a rooted phone. https://developer.android.com/reference/android/Manifest.permission.html#CALL_PRIVILEGED

If user has granted permission android.permission.CALL_PHONE to your app, you can call directly to any number using ACTION_CALL , if user has not granted permission to make call you can check and process with ACTION_DIAL as:

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
    intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:+91100"));
    startActivity(intent);
} else {
    intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+91100"));
    startActivity(intent);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM