androidsmsmanager

security threat warning when I use SmsManager


I have to create an android App that can send message automatically. I found the code that do what I want but this send me the following warning [it is a translation since my message it is not in english]:

security threat
AppName seems to be infected. We advise you to uninstall the app immediately.

The line that give me the warning is:

smsManager.sendTextMessage(phoneNo, null, message, null, null);

My code is:

public void sendSMSMessage() {
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.SEND_SMS)
            != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.SEND_SMS)) {
        } else {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.SEND_SMS},
                    MY_PERMISSIONS_REQUEST_SEND_SMS);
        }
    }
}

@Override
public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_SEND_SMS: {
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                SmsManager smsManager = SmsManager.getDefault();
                smsManager.sendTextMessage(phoneNo, null, message, null, null);
                Toast.makeText(getApplicationContext(), "SMS sent.",
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(getApplicationContext(),
                        "SMS faild, please try again.", Toast.LENGTH_LONG).show();
                return;
            }
        }
    }
}

I want to point out that this code work. The only problem is that warning that I would like to eliminate.

I tried to send sms with intent but those method need human interaction and I do not want it (if possible).

Thanks in advance.


Solution

  • Google has changed its security policies for dangerous permissions. As per it, you cant allow your app to handle such events without human interactions as these are dangerous permissions.

    Google Play restricts the use of high risk or sensitive permissions, including the SMS or Call Log permission groups.

    Check this link for further information on the same:

    https://support.google.com/googleplay/android-developer/answer/9047303?hl=en