Emerick
Emerick

Reputation: 309

Make a call on Android 10

i made an app that automatically makes a call if a pre configured code arrives in SMS.

I originally build this app on Android 9 and it worked well as long as i'm using Android 9, but my phone upgraded to Android 10 version and it just stopped working.

Analysing the logs and debuging the app, not a single error message happens. Debuging everything works fines and i call the acctivity as follows:

Intent in = new Intent(Intent.ACTION_CALL);
in.setData(Uri.parse(callPhone));
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in);

But nothing happens. Its just doesnt make the call. I installed in other devices using other versions of android and still works, but not in Android 10.

Anyone knows if something different was implemented or if theres a new way to make a call on Android 10 version?

*NOTE: I also tried to update the code to use androidx library as changed to use targetSdkVersion 29, but still the same.

Upvotes: 4

Views: 860

Answers (1)

Eren Tüfekçi
Eren Tüfekçi

Reputation: 2511

Android 10 restricted to starting activity from background. There are some exclusions for this. In my view asking for "SYSTEM_ALERT_WINDOW" permission is the easiest one. Hope it helps.

https://developer.android.com/guide/components/activities/background-starts

https://stackoverflow.com/a/59421118/11982611

In manifest :

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

Somewhere in your code

private void RequestPermission() {
            // Check if Android M or higher
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                // Show alert dialog to the user saying a separate permission is needed
                // Launch the settings activity if the user prefers
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                        Uri.parse("package:" + getActivity().getPackageName()));
                startActivityForResult(intent, ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE);
            }
        }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (!Settings.canDrawOverlays(getContext())) {
                    PermissionDenied();
                }
                else
                {
                 //Permission Granted-System will work
            }

        }
    }

Upvotes: 5

Related Questions