Z
Z
zeuss562018-04-13 17:48:52
Android
zeuss56, 2018-04-13 17:48:52

How to send SMS to Android API without dialog appearing?

How to send SMS on Android bypassing the send request so that the user does not see the dialog "Send SMS? This may cost you money"? Is this possible in principle on a non-rooted device with Android 5.0+?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Marken, 2018-04-13
@zeuss56

Regardless of whether you change the default application or not, the dialog for accessing the system function will still be there.
Permission details can be found here .
Try to make the application "Device Administrator".
For a long time I have been making a corporate device control system with the ability to remotely reset passwords and completely clear data through our web interface. The solution was this opportunity.
In AndroidManifest:

<uses-feature
        android:name="android.software.device_admin"
        android:required="true"/>

    <application
       .........
        <receiver
            android:name=".Receiver.AdminReceiver"
            android:permission="android.permission.BIND_DEVICE_ADMIN">
            <meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_admin"/>

            <intent-filter>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
                <action android:name="android.app.action.ACTION_PASSWORD_CHANGED"/>
                <action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
                <action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
                <action android:name="android.permission.WRITE_SECURE_SETTINGS"/>
                <action android:name="android.permission.WRITE_SETTINGS" />
            </intent-filter>
        </receiver>

In .Receiver.AdminReceiver.java:
import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class AdminReceiver extends DeviceAdminReceiver {
  @Override
  public void onEnabled(Context ctxt, Intent intent) {
    ComponentName cn=new ComponentName(ctxt, AdminReceiver.class);
    DevicePolicyManager mgr=
        (DevicePolicyManager)ctxt.getSystemService(Context.DEVICE_POLICY_SERVICE);

    mgr.setPasswordQuality(cn,
                           DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
    
    onPasswordChanged(ctxt, intent);
  }

  @Override
  public void onPasswordChanged(Context ctxt, Intent intent) {
    DevicePolicyManager mgr=
        (DevicePolicyManager)ctxt.getSystemService(Context.DEVICE_POLICY_SERVICE);
    String msgId = "";

    if (mgr.isActivePasswordSufficient()) {
      msgId="Ok";
    }
    else {
      msgId="Fail";
    }

    Toast.makeText(ctxt, msgId, Toast.LENGTH_LONG).show();
  }

  @Override
  public void onPasswordFailed(Context ctxt, Intent intent) {

  }

  @Override
  public void onPasswordSucceeded(Context ctxt, Intent intent) {

  }
}

Create " res/xml/device_admin.xml " and put in it:
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">

  <uses-policies>
    <limit-password />
    <watch-login />
    <reset-password />
    <force-lock />
    <wipe-data />
    <expire-password />
    <encrypted-storage />
  </uses-policies>

</device-admin>

The "intent-filter" tag specifies privileges, you can find a complete list of them on Google.
After installing the application, you need to go to Settings->Security->Device Administrators->Enable the application.
Accordingly, AdminReceiver.java will need to be adjusted to suit your needs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question