Android: call number without init user?

For something like “help, I can’t get up” the application - is there a way for the user to set a contact number, and then for the application to call this number in the future WITHOUT the user initiating the dialout? I tried below, but there seems to be a problem:

 private void callPhone(){
            if(phoneNumber.length()>0){
                try {
                       Intent intent = new Intent(Intent.ACTION_CALL);
                       intent.setData(Uri.parse("tel:"+phoneNumber));
                       startActivity(intent);
                    } catch (Exception e) {
                        Toast.makeText(getApplicationContext(), "Problem calling number.", Toast.LENGTH_LONG).show();
                    }
                //startActivityForResult(new Intent(Intent.ACTION_CALL, Uri.parse("tel:+"+phoneNumber)), 1);
            }

        }
+3
source share
1 answer

To obtain the permission required to place calls without using the dialer and requiring the user to confirm the call, you must set either CALL_PHONE or CALL_PRIVILEGED in your file AndroidManifest.xmldepending on your needs.

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

or

<uses-permission android:name="android.permission.CALL_PRIVILEGED" />
+5

Source: https://habr.com/ru/post/1764413/


All Articles