Send a WhatsApp message in the background or send a message and close the application in android

Is it possible to send a whatsApp message without opening an application that will be sent in the background, for example, by sending an SMS using:

smsManager.sendTextMessage("+12546304580", null, "Test Message", null, null);

if so, how? The code I tried opens APP (WITH INTENT):

    Intent waIntent = new Intent(Intent.ACTION_SEND);
    waIntent.setType("text/plain");
    String text = "Test Message";
    waIntent.setPackage("com.whatsapp");
    waIntent.putExtra(Intent.EXTRA_TEXT, text);//
    startActivity(Intent.createChooser(waIntent, "Share with"));

Or is it possible to open the application to send a message to the specified address and close it?

Thank!

+4
source share
3 answers

No, this is not possible, since Whatsapp does not offer ContentProviders and will get used to it in the future.

Re-disassembly and implementation of the jabber-based protocol is possible.

You will need to handle a handshake, etc.

, , root, .

- (, Whatsapp ):

Accesibility, . :

public static final String FACEBOOK_PACKAGE_NAME = "com.facebook.orca";

public class DefaultAccessibility extends AccessibilityService {
  @Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    final int eventType = event.getEventType();
    try {
        if (Build.VERSION.SDK_INT >= 16) {
            switch (eventType) {
                case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
                Notification notification = (Notification) event.getParcelableData();
                if (event.getPackageName().equals(WHATSAPP_PACKAGE_NAME)) {
                        RemoteViews views = notification.bigContentView;
                        Class<?> secretClass = views.getClass();
                        ArrayList<String> raw = new ArrayList<String>();
                        Field outerFields[] = secretClass.getDeclaredFields();
                        for (Field outerField : outerFields) {
                            if (outerField.getName().equals("mActions")) {
                                outerField.setAccessible(true);
                                ArrayList<Object> actions = null;
                                try {
                                actions = (ArrayList<Object>) outerField.get(views);
                                for (Object action : actions) {
                                Field innerFields[] = action.getClass()getDeclaredFields();

                                        Object value = null;
                                        Integer type = null;
                                        for (Field field : innerFields) {
                                            try {
                                                field.setAccessible(true);
                                                if (field.getName().equals("type")) {
                                                    type = field.getInt(action);
                                                } else if (field.getName().equals("value")) {
                                                    value = field.get(action);
                                                }
                                            } catch (IllegalArgumentException e) {
                                            } catch (IllegalAccessException e) {
                                            }
                                        }

                                        if (type != null && type == 10 && value != null) {
                                            raw.add(value.toString());
                                        }
                                    }
                                } catch (IllegalArgumentException e1) {
                                } catch (IllegalAccessException e1) {
                                }
                            }
                            parseWhatsappRawMessages(raw);

                        }
                }
}

.

private void parseWhatsappRawMessages(ArrayList<String> raw) {

        int count = raw.size();
        if (count > 2) {
                Log.d(TAG, "RAW TITLE: " + raw.get(0));
                Log.d(TAG, "RAW MESSAGE: " + raw.get(1));
        }
}

, .

accesibilityService .        

    <service
        android:name="com.app.DefaultAccessibility"
        android:enabled="true"
        android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
        <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService"></action>
        </intent-filter>
        <meta-data
            android:name="android.accessibilityservice"
            android:resource="@xml/accessibilityservice"/>
    </service>

xml/accesibilityservice.xml , .

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackAllMask"
android:notificationTimeout="100"
android:description="@string/accessibility_service_description" />

. ,

Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivityForResult(intent, 1337);
+4

, , , . SMS WhatsApp . SMS .

, WhatsAap, , , . , n , .

0

, Android Wear, Quick for Wear Whatsapp, Messenger, Gmail .. .

0

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


All Articles